The Problem
Make a simple program that reads two variables named A, B. Calculate and print the difference of A and B (A - B).
Input Specification
Input file will contain only two integer A and B (0<A, B<100 and A>B)
Output Specification
Output will show the difference of A and B in a separate line.
Sample Input
13 5
Sample Output
8
The solution of the program
I think you already know that. :)
Now the problem is same but just change the input specification and output specification
The Problem
Make a simple program that reads two variables named A, B. Calculate and print the difference of A and B (A - B).
Input Specification
Input file consist of several test cases. Each test case contains a line and each line will contains two integers A and B (0<A, B<100 and A>B). Input is terminated by EOF.
Output Specification
For each test case you should output a line. This line contains the value of the difference of A and B.
Sample Input
13 5
10 5
50 23
80 78
Sample Output
8
5
27
2
Now the solution of the program
Did you find the difference between the two solutions?
It's easy, just you need to add a while
while( there you need to add scanf() function )
{
Other codes here
}
Why scanf(“%d %d”,&a,&b)==2 ?
- Because you are inputting two value.
If you input 3 integers then scanf(“%d %d %d”,&x,&y,&z)==3
Example
while(scanf(“%d %d %d”,&x,&y,&z)==3)
{
Other code here
}
The differences are
I think you understand how can we input multiple lines and output multiple lines.
If you are not clear about the process please contact with me.
Prepared by: Shahin ShamS