#include <iostream>using namespace std;int main(){int a,b,c;cin>>a>>b>>c;cout<<"a+b+c";return 0;}這個程序,我運行時輸入 11 22 33結果卻還是a+b+c而不是11+22+33的值66
3 回答

Qyouu
TA貢獻1786條經驗 獲得超11個贊
C++中實現a+b+c求和的方法有二種,分別如下:
方法1,把三個數加起來,賦給d, 把 d 打印出來。
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> #include <stdlib.h> main(){ int a,b,c,d; printf("please input a b c:\n"); scanf("%d %d %d",&a,&b,&c); d = a+b+c; printf("%d\n",d); return 0; } |
方法2,直接打印 表達式 a+b+c 的值。
1 2 3 4 5 6 7 8 9 | #include <stdio.h> #include <stdlib.h> main(){ int a,b,c,d; printf("please input a b c:\n"); scanf("%d %d %d",&a,&b,&c); printf("%d\n",a+b+c); return 0; } |
- 3 回答
- 0 關注
- 603 瀏覽
添加回答
舉報
0/150
提交
取消