1001 A + B Problem, 1001 problem
Basic Input and Output Functions
1 #include <stdio.h>2 3 int main(){4 int a,b;5 while(scanf("%d %d",&a,&b)>=0){6 printf("%d\n",a+b);7 }8 return 0;9 }
ZOJ Problem Set-1001: A + B Problem?
# Include <stdio. h>
Int main ()
{
Int a, B;
While (scanf ("% d", & a, & B )! = EOF)
Printf ("% d \ n", a + B );
Return 0;
}
The main program should return int.
A + B Problem II-HDOJ 1002
# Include <iostream> # include <cstring> using namespace std; char CA [1000], CB [1000]; int IA [1001]; int main () {int n, m1 = 0, m2 = 0, c, s = 1, I, j, k, num; cin> n; while (n --) {scanf ("% s", CA, CB); m1 = strlen (CA); m2 = strlen (CB); c = 0; for (I = m1-1, j = m2-1, k = 0; j> = 0 & I> = 0; I --, j --, k ++) {num = CA [I]-'0' + CB [j]-'0' + c; IA [k] = num % 10; c = num/10 ;} if (j> I) {while (j> = 0) {num = CB [j]-'0' + c; IA [k] = num % 10; c = num/10; k ++, j -- ;}} else if (I> j) {while (I> = 0) {num = CA [I]-'0' + c; IA [k] = num % 10; c = num/10; k ++, I --;}} else if (c) IA [k ++] = c; cout <"Case" <s <": \ n "; cout <CA <"+" <CB <"="; for (I = k-1; I> = 0; I --) cout <IA [I]; cout <endl; s ++;} return 0 ;}