基本輸入輸出函數
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 }
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
return 0;
}
主程序應返回int。
#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%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;}