llgd.net
当前位置:首页 >> C语言 从键盘输入两个整数,求这两个整数的和和差... >>

C语言 从键盘输入两个整数,求这两个整数的和和差...

代码如下: #include "stdio.h" void main() { int a,b; printf("请输入两个整数(a,b):"); scanf("%d,%d",&a,&b); printf("和:%d\n",a+b); printf("差:%d\n",a-b); }

#include void main() { int a,b,m; printf("Input a,b please!:"); scanf("%d%d",&a,&b); m=a-b; printf("%d\nok",a-b); }

除数为0时怎样做、不为0时怎样做,不用分支结构是处理不了这种问题的,亲。

#include int main(){int a,b,c; char op; scanf("%d%c%d",&a,&op,&b); switch(op) {case'+':c=a+b; break; case'-':c=a-b; break; case'*':c=a*b; break; case'/':if(b)c=a/b; else {printf("除数不能为!0\n");return 0;} } printf("%d%c%d=%d\...

#include "windows.h" #include "stdio.h" int Add(int a, int b) { return a + b; } int Sub(int a, int b) { return a - b; } int Mul(int a, int b) { return a * b; } float Div(int a, int b) { if(b == 0) return 0; return (float)a / b;...

#include int main(void) { int a, b; printf("\nInput a: "); scanf("%d", &a); printf("\nInput b: "); scanf("%d", &b); printf("the sum is : %d \n", a + b); printf("the cha is : %d \n", a > b ? a - b : b - a); return 0;}

#include int fun(int a,int b, int *psub){ int sum; sum=a+b; *psub = a-b; return sum;}void main( ){ int x,y,s1,s2; scanf("%d %d", &x, &y);s1=fun(x,y, &s2); printf("sum=%d\nsub = %d\n", s1, s2);}//程序应该改成这样,该怎么填自己看...

#include void main() { int a, b; int m, n; scanf("%d%d", &a, &b); if (a < b) m = b - a - 1; /* 计算a,b间整数个数 */ else m = a - b - 1; /* a,b间的整数,不包括a,b */ n = (int)(1.0 * (a + b) * m / 2 ); /* 乘1.0是让运算成小数,不...

类型搞错,浮点数不支持求余数,而且浮点数不是用 %d ,而是%f int x,y; scanf("%d%d",&x,&y); printf("%d %d %d %f %d\n" ,x+y , x-y, x*y , (float)x / (float) y, x%y );

你要using namespace std; 才能使用cout、cin、endl

网站首页 | 网站地图
All rights reserved Powered by www.llgd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com