其他分享
首页 > 其他分享> > 用c编写一个简单的计算器

用c编写一个简单的计算器

作者:互联网

#include<stdio.h>
int main()
{
	int value1,value2;
	char op;
	scanf("%d%c%d",&value1,&op,&value2);
	switch(op){
	case'+':
		printf(" =%d\n",value1+value2);
		break;
		case'-':
		printf(" =%d\n",value1-value2);
		break;
		case'*':
		printf(" =%d\n",value1*value2);
		break;
		case'/':
			if(value2!=0){
			printf(" =%d\n",value1/value2);
			}else{
				printf("Divisor can not be 0!\n");
			}
  			break;
  		case'%':
			if(value2!=0){
			printf(" =%d\n",value1%value2);
			}else{
				printf("Divisor can not be 0!\n");
			}
			break;
  			default:
  				printf("Unknown operator\n");
  				break;
	}
			return 0;
 } 

标签:case,简单,break,value2,value1,printf,编写,op,计算器
来源: https://blog.csdn.net/weixin_60483861/article/details/120852751