c语言小程序 输入两位数实现加减乘除 保留两位小数

c语言小程序 输入两位数实现加减乘除 保留两位小数,第1张

#include<stdio.h>

it main()

{int a,b

scanf("%d%d",&a,&b)

printf("%d+%d=%d\n",a+b)

printf("%d-%d=%d\n",a-b)

printf("%d*%d=%d\n",a*b)

printf("%d/%d=%.2f\n",(float)a/b)

return 0

}

#include<stdio.h>

#include<stdlib.h>

main()

{

float a,b,rechar c printf("input(like 12+15 or 12*15):\n") scanf("%f",&a)

do{

scanf("%c",&c)}while(c == ' ')scanf("%f",&b) switch(c)

{

case '+': re = a+bbreakcase '-': re = a-bbreakcase '*': re = a*bcase '/': re = a/bdefault: break

}

printf("output the result:%.1f\n",re)system("pause")

}

输入示例: 2+3(or 2*3 or 2-3 or 2/3)

是要这样的吗?

#include<stdio.h>

main()

{

int i,sum=0

for(i=1i<=9i++)

{

sum=sum+i

printf("%d+",i)

}printf("%d=%d\n",i,sum)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12193142.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存