c语言求教 编程实现10道+,-,*,/的运算
展开全部
#include<stdio.h>
#include<ctype.h>
#include<math.h>
void f2()
{
int i=1,t=1,a;
scanf("%d",&a);
while(i<=a)
{
t*=i;
i++;
}
printf("!=%d",t);
}
void main()
{
int a,b;
char d;
do
{
printf("input expression: a+(-,*,/,^,s,!)b\n");
scanf("%d %d",&a,&b);
printf("Please select operation way: (-,*,/,^,s,!)\n");
scanf("%s",&d);
switch(d)
{
case'+':
printf("a+b=%d\n",a+b);
break;
case'-':
printf("a-b=%d\n",a-b);
break;
case'*':
printf("a*b=%d\n",a*b);
break;
case'/':
printf("a/b=%d\n",a/b);
break;
case's':
if(a<0)
printf("error!");
printf("=%.6f\n",sqrt((float)a));
break;
case'^':
//printf("=%f\n",f1(a,b));
printf("a^b=%d\n",a^b);
break;
case'!':
f2();
break;
default:
printf("input error\n");
}
printf("Do you want to continue(Y/N or y/n)");
fflush(stdin);
}
while(toupper(getchar())=='Y');
}
这是一个关于四则运算的简单小程序,不知道满不满足你的要求
#include<ctype.h>
#include<math.h>
void f2()
{
int i=1,t=1,a;
scanf("%d",&a);
while(i<=a)
{
t*=i;
i++;
}
printf("!=%d",t);
}
void main()
{
int a,b;
char d;
do
{
printf("input expression: a+(-,*,/,^,s,!)b\n");
scanf("%d %d",&a,&b);
printf("Please select operation way: (-,*,/,^,s,!)\n");
scanf("%s",&d);
switch(d)
{
case'+':
printf("a+b=%d\n",a+b);
break;
case'-':
printf("a-b=%d\n",a-b);
break;
case'*':
printf("a*b=%d\n",a*b);
break;
case'/':
printf("a/b=%d\n",a/b);
break;
case's':
if(a<0)
printf("error!");
printf("=%.6f\n",sqrt((float)a));
break;
case'^':
//printf("=%f\n",f1(a,b));
printf("a^b=%d\n",a^b);
break;
case'!':
f2();
break;
default:
printf("input error\n");
}
printf("Do you want to continue(Y/N or y/n)");
fflush(stdin);
}
while(toupper(getchar())=='Y');
}
这是一个关于四则运算的简单小程序,不知道满不满足你的要求
展开全部
int a = 1;
int b = 2;
int c ;
c= a+b;
c = a* b;
c = a-b;
c = a/b;
c = a+b/a;
c = a+b*a;
c = a- b/a;
c = a-b*a;
c = b + a/b;
c = b - a/b;
int b = 2;
int c ;
c= a+b;
c = a* b;
c = a-b;
c = a/b;
c = a+b/a;
c = a+b*a;
c = a- b/a;
c = a-b*a;
c = b + a/b;
c = b - a/b;
追问
怎么编成一个程序
追答
void main(void) {
int a = 1;
int b = 2;
int c ;
c= a+b;
c = a* b;
c = a-b;
c = a/b;
c = a+b/a;
c = a+b*a;
c = a- b/a;
c = a-b*a;
c = b + a/b;
c = b - a/b;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询