Input output sample - 03Input Specification:Input file consist of several test cases. Each test case contains a line and each line will contains two integers a and b(b>0). Input is terminated by EOF. Output Specification: For each test case you should output a line. This line contains the value of c wherec=a%b. You should print a blank line between two consecutive test cases. Sample Input: 3 2 2 3 1 1 Sample Output: 1 2 0 Pascal Code : program sample3 (input,output); var a,b,c,temp : integer; begin temp:=0; while not eof(input) do begin readln(a,b); c:= a MOD b; if temp=1 then writeln(''); writeln(c); temp:=1; end; end. C Code : #include <stdio.h> int main(){ int a,b,c,temp=0; while(scanf("%d %d",&a,&b)==2){ c = a%b; if(temp) printf("\n"); printf("%d\n",c); temp=1; } return 0; } C++ Code : #include <iostream> using namespace std; int main(){ int a,b,c,temp=0; while(cin>>a>>b){ c=a%b; if(temp) cout<<endl; cout<<c<<endl; temp=1; } return 0; } Java Code :
import java.io.*; import java.util.*; class Main{ public static void main (String args[])throws IOException{ BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer token; String input; int a,b,c,temp=0; while((input = bf.readLine())!=null){ token = new StringTokenizer(input); a = Integer.parseInt(token.nextToken()); b = Integer.parseInt(token.nextToken()); c = a%b; if(temp==1) System.out.println(); System.out.println(c); temp=1; } } } |
||