C语言编程实现简易计算器
生活随笔
收集整理的這篇文章主要介紹了
C语言编程实现简易计算器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
輸入格式為(%d %d %c)來進行簡單的計算器編程
用switch來解決:
#include<stdio.h>int main() { int date1,date2,result; char op; scanf("%d %d %c",&date1,&date2,&op);switch(op){case '+':result=date1+date2;printf("%d",result);break;case '-':result=date1-date2;printf("%d",result);break;case '*':result=date1*date2;printf("%d",result);break;case '/':result=date1/date2;printf("%d",result);break;}return 0;}?用if語句去完成:
#include<stdio.h>int main() { int date1,date2,result; char op; scanf("%d %d %c",&date1,&date2,&op);if(op=='+'){result=date1+date2;printf("%d",result);}if(op=='-'){result=date1-date2;printf("%d",result);}if(op=='*'){result=date1*date2;printf("%d",result);}if(op=='/'){result=date1/date2; printf("%d",result);}return 0;}總結
以上是生活随笔為你收集整理的C语言编程实现简易计算器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kitty用HTML和css咋做,使用
- 下一篇: HR团队如何提升效率?人力资源RPA给你