输入两个整数,进行加减乘除四则运算的c语言程序怎么写啊,拜托了~

2024-11-16 16:54:54
推荐回答(3个)
回答(1):

#include

void function(int a, int b)
{
printf("%d add %d = %d\n",a, b, a+b); //加法运算
printf("%d sub %d = %d\n",a, b, a-b); //加法运算
printf("%d mul %d = %d\n",a, b, a*b); //乘法运算
printf("%d div %d = %d\n",a, b, a/b); //除法运算
}

int main()
{
int a,b;
printf("please input a and b");
scanf("%d%d",&a,&b);
function(a,b);
return 0;
}

回答(2):

#include
#include
#include
using namespace std;
main(void)
{
float a,b;
char ch;
while(1)
{
cin>>a>>ch>>b;
//scanf("%d%c%d",&a,&ch,&b);
if(ch=='+')
//printf("= %f \n",a+b);
cout<<"="< if(ch=='-')
//printf("= %f \n",a-b);
cout<<"="< if(ch=='*')
//printf("= %f \n",a*b);
cout<<"="< if(ch=='/')
//printf("= %f \n",a/b);
cout<<'='< system("cls");
}
return 0;
}