c语言:加减乘除运算,要求:输入(通过键盘输入两整数给a和b,比如4和3...

发布网友 发布时间:2024-10-24 16:09

我来回答

3个回答

热心网友 时间:2024-11-10 08:26

//看你的意思应该是一个计算器吧
//我的自制计算器如下:
#include<stdio.h>
#include<math.h>
#include<string.h>
main()
{ for(;;)
{
int n;
int t;
float a,b;
system("cls");
printf(" ===========》简易计算器《==========\n\n");
printf(" ====1.执行加法运算 ====\n");
printf(" ====2.执行减法运算 ====\n");
printf(" ====3.执行乘法运算 ====\n");
printf(" ====4.执行除法运算 ====\n");
printf(" ====5.执行正弦运算 ====\n");
printf(" ====6.执行余弦运算 ====\n");
printf(" ====7.执行正切运算 ====\n");
printf(" ====8.执行以e为底的对数运算 ====\n");
printf(" ====9.执行以10为底的对数运算 ====\n");
printf(" ====10.执行幂函数运算 ====\n");
printf(" ===================================\n");
printf(" ===================================\n\n");
printf("请选择(1-10):");
a: scanf("%d",&n);
if(n<1||n>10)
{
printf("输入错误!请重新输入:\n");
goto a;
}
switch(n)
{
case 1:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f+%4.2f=%-4.2f\n",a,b,a+b);
system("pause");break;
}
case 2:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f-%4.2f=%-4.2f\n",a,b,a-b);
system("pause");break;
}
case 3:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f*%4.2f=%4.2f\n",a,b,a*b);
system("pause");break;
}
case 4:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f/%4.2f=%4.2f\n",a,b,a/b);
system("pause");break;
}
case 5:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("sin(%4.3f)=%4.2f\n",a,sin(a));
system("pause");break;
}
case 6:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("cos(%4.3f)=%4.2f\n",a,cos(a));
system("pause");break;
}
case 7:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("tan(%4.3f)=%4.2f\n",a,tan(a));
system("pause");break;
}
case 8:
{ printf("请输入要求lnx的x的值为:\n");
scanf("%f",&a);
printf("ln(%4.3f)=%4.2f\n",a,log(a));
system("pause");break;
}
case 9:
{ printf("请输入要求的以10为底X的对数的X的值为:\n");
scanf("%f",&a);
printf("sin(%4.3f)=%4.2f\n",a,log10(a));
system("pause");break;
}
case 10:
{ printf("请输入幂函数的底数X和次数Y:");
scanf("%f%f",&a,&b);
printf("底数为%4.3f,次数为:%4.3f的幂函数的值为:%4.2f\n",a,b,pow(a,b));
system("pause");break;
}
case 11:
{ printf("请输入要求绝对值的复数:\n");
t: scanf("%4.3f",&a);
if(a>=0)
{
printf("对不起!请输入一个负数!\n");
goto t;
}
printf("%4.3f的绝对值为:%4.2f\n",t,fabs(a));
system("pause");break;
}
}
}
}

//希望你喜欢!!!!
//==========================================================Mr_computer

热心网友 时间:2024-11-10 08:23

#include<stdio.h>
#include<math.h>
int main()
{
int a , b ;
char c ;
scanf("%d%d" , &a ,&b ) ;
printf("a+b=%d %d+%d=%d\n" , a+b , a , b , a+b ) ;
printf("a-b=%d %d-%d=%d\n" , a-b , a ,b , a-b ) ;
printf("a*b=%d %d*%d=%d\n" , a*b , a , b ,a*b ) ;
if(b != 0 )
printf("a/b=%d %d/%d=%d\n" , a/b , a , b , a/b ) ;
else
printf("b=0\n") ;
return 0 ;
}

热心网友 时间:2024-11-10 08:24

#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d+%d=%d\n", a, b, a + b);
printf("%d-%d=%d\n", a, b, a - b);
printf("%d*%d=%d\n", a, b, a * b);
if (b == 0)
{
printf("除数为0\n");
return 0;
}
printf("%d/%d=%d\n", a, b, a / b);
return 0;
}

热心网友 时间:2024-11-10 08:31

//看你的意思应该是一个计算器吧
//我的自制计算器如下:
#include<stdio.h>
#include<math.h>
#include<string.h>
main()
{ for(;;)
{
int n;
int t;
float a,b;
system("cls");
printf(" ===========》简易计算器《==========\n\n");
printf(" ====1.执行加法运算 ====\n");
printf(" ====2.执行减法运算 ====\n");
printf(" ====3.执行乘法运算 ====\n");
printf(" ====4.执行除法运算 ====\n");
printf(" ====5.执行正弦运算 ====\n");
printf(" ====6.执行余弦运算 ====\n");
printf(" ====7.执行正切运算 ====\n");
printf(" ====8.执行以e为底的对数运算 ====\n");
printf(" ====9.执行以10为底的对数运算 ====\n");
printf(" ====10.执行幂函数运算 ====\n");
printf(" ===================================\n");
printf(" ===================================\n\n");
printf("请选择(1-10):");
a: scanf("%d",&n);
if(n<1||n>10)
{
printf("输入错误!请重新输入:\n");
goto a;
}
switch(n)
{
case 1:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f+%4.2f=%-4.2f\n",a,b,a+b);
system("pause");break;
}
case 2:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f-%4.2f=%-4.2f\n",a,b,a-b);
system("pause");break;
}
case 3:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f*%4.2f=%4.2f\n",a,b,a*b);
system("pause");break;
}
case 4:
{ printf("请输入:a,b两个数的值:\n");
scanf("%f%f",&a,&b);
printf("%4.2f/%4.2f=%4.2f\n",a,b,a/b);
system("pause");break;
}
case 5:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("sin(%4.3f)=%4.2f\n",a,sin(a));
system("pause");break;
}
case 6:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("cos(%4.3f)=%4.2f\n",a,cos(a));
system("pause");break;
}
case 7:
{ printf("请输入要求的值为:\n");
scanf("%f",&a);
printf("tan(%4.3f)=%4.2f\n",a,tan(a));
system("pause");break;
}
case 8:
{ printf("请输入要求lnx的x的值为:\n");
scanf("%f",&a);
printf("ln(%4.3f)=%4.2f\n",a,log(a));
system("pause");break;
}
case 9:
{ printf("请输入要求的以10为底X的对数的X的值为:\n");
scanf("%f",&a);
printf("sin(%4.3f)=%4.2f\n",a,log10(a));
system("pause");break;
}
case 10:
{ printf("请输入幂函数的底数X和次数Y:");
scanf("%f%f",&a,&b);
printf("底数为%4.3f,次数为:%4.3f的幂函数的值为:%4.2f\n",a,b,pow(a,b));
system("pause");break;
}
case 11:
{ printf("请输入要求绝对值的复数:\n");
t: scanf("%4.3f",&a);
if(a>=0)
{
printf("对不起!请输入一个负数!\n");
goto t;
}
printf("%4.3f的绝对值为:%4.2f\n",t,fabs(a));
system("pause");break;
}
}
}
}

//希望你喜欢!!!!
//==========================================================Mr_computer

热心网友 时间:2024-11-10 08:28

#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d+%d=%d\n", a, b, a + b);
printf("%d-%d=%d\n", a, b, a - b);
printf("%d*%d=%d\n", a, b, a * b);
if (b == 0)
{
printf("除数为0\n");
return 0;
}
printf("%d/%d=%d\n", a, b, a / b);
return 0;
}

热心网友 时间:2024-11-10 08:24

#include<stdio.h>
#include<math.h>
int main()
{
int a , b ;
char c ;
scanf("%d%d" , &a ,&b ) ;
printf("a+b=%d %d+%d=%d\n" , a+b , a , b , a+b ) ;
printf("a-b=%d %d-%d=%d\n" , a-b , a ,b , a-b ) ;
printf("a*b=%d %d*%d=%d\n" , a*b , a , b ,a*b ) ;
if(b != 0 )
printf("a/b=%d %d/%d=%d\n" , a/b , a , b , a/b ) ;
else
printf("b=0\n") ;
return 0 ;
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com