1000
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
要点:注意审题,EOF。
#include <stdio.h>
int main(){
int a, b;
while(scanf("%d%d",&a,&b)!=EOF){
printf("%d\n",a+b);
}
return 0;
}
1089
Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
Sample Output
6
30
代码和1000一样。
1090
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
2
1 5
10 20
Sample Output
6
30
要点:注意循环条件吧
#include <stdio.h>
int main(){
int linenum;
scanf("%d",&linenum);
for(;linenum!=0;linenum--){
int a,b;
scanf("%d %d",&a,&b);
printf("%d\n",a+b);
}
return 0;
}
1091
Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
0 0
Sample Output
6
30
要点:||和&&的用法
#include <stdio.h>
int main(){
int a,b;
while((scanf("%d%d",&a,&b)!=EOF)&&(a!=0||b!=0)){
printf("%d\n",a+b);
}
return 0;
}
1095
代码与1089只差printf加一个\n
1001
Input
The input will consist of a series of integers n, one integer per line.
Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.
Sample Input
1
100
Sample Output
1
5050
要点:1. 注意换行。2.注意循环
#include <stdio.h>
int main(){
int a;
int sum = 0;
while(scanf("%d",&a)!=EOF){
printf("%d\n\n",sumer(a));
}
return 0;
}
int sumer(int a){
int adder = 1;
int sum = 0;
while(adder!=a+1){
sum = sum+adder;
adder++;
}
return sum;
}
1064
Input
The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.
Output
The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.
Sample Input
100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75
Sample Output
$1581.42
#include <stdio.h>
int main(){
int i;
double sum=0.0;
for(i=0;i<12;i++){
double input;
scanf("%lf",&input);
sum = sum+input;
}
sum = sum/12.0;
printf("$%.2f\n",sum);
return 0;
}