Input _ Class 1:
The Input does not indicate the number of Input blocks. The End mark is EOF.
Example 1:
Description:
Your task is to calculate a + B
Input
The input contains multiple rows of data. Each row has two integers, a and B, separated by spaces.
Output
For each pair of integers a and B, output their sum. Each sum occupies a row.
Sample Input
1 5
10 20
Sample Output
6
30
# Include <stdio. h>
Int main ()
{
Int a, B;
While (scanf ("% d", & a, & B )! = EOF) printf ("% d \ n", a + B );
}
Enter a solution for this category:
C Syntax:
While (scanf ("% d", & a, & B )! = EOF)
{
....
}
C ++ Syntax:
While (cin> a> B)
{
....
}
Note:
1. the return value of the Scanf function is the number of variables read, for example, scanf ("% d", & a, & B );
If there is only one integer input, the return value is 1. If there are two integers, the return value is 2. If none of them exist, the return value is-1.
2. EOF is a predefined constant, which is equal to-1.
Input _ Class 2:
The Input will start with N Input blocks, followed by N Input blocks.
Example 2:
Description:
Your task is to calculate a + B
Input
The input contains multiple rows of data. The first row has an integer N, And the next N rows have two integers a and B, separated by spaces.
Output
For each pair of integers a and B, output their sum. Each sum occupies a row.
Sample Input
2
1 5
10 20
Sample Output
6
30
# Include <stdio. h>
Int main ()
{
Int n, I, a, B;
Scanf ("% d", & n );
For (I = 0; I <n; I ++)
{
Scanf ("% d", & a, & B );
Printf ("% d \ n", a + B );
}
}
Enter a solution for this category:
C Syntax:
Scanf ("% d", & n );
For (I = 0; I <n; I ++)
{
....
}
C ++ Syntax:
Cin> n;
For (I = 0; I <n; I ++)
{
....
}
Input _ Category 3:
The Input does not indicate the number of Input blocks, but ends with a special Input.
Example 3:
Description:
Your task is to calculate a + B
Input
The input contains multiple rows of data. Each row has two integers, a and B, separated by spaces. The test data ends at 0.
Output
For each pair of integers a and B, output their sum. Each sum occupies a row.
Sample Input
1 5
10 20
0 0
Sample Output
6
30
# Include <stdio. h>
Int main ()
{
Int a, B;
While (scanf ("% d", & a, & B )&&! (A = 0 & B = 0 ))
Printf ("% d \ n", a + B );
}
Enter a solution for this category:
C Syntax:
While (scanf ("% d", & n) & n! = 0)
{
....
}
C ++ Syntax:
While (cin> n & n! = 0)
{
....
}
Input _ Class 4:
Combination of the above situations
Example 4:
Description:
Your task is to calculate the sum of multiple numbers
Input
The input contains multiple rows of data. Each row starts with an integer N, followed by N integers separated by spaces. The test data ends with 0.
Output
Output the sum of N integers in each row. Each sum occupies one row.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15