文章
145
粉丝
217
获赞
21
访问
82.0k
#include <stdio.h>
//阶乘
long long Factorial(int n)
{
long long i = 1,sum = 1;
for(i = 1; i <= n; i++)
sum *= i;
return sum;
}
int main()
{
int a,b;
char c;
while(scanf("%d %c",&a,&c) != EOF)
{
if(c != '!') scanf(" %d",&b);
if(c == '!')
printf("%lld\n",Factorial(a));
else
{
switch(c)
{
case '+':printf("%d\n",a+b);break;
case '-':printf("%d\n",a-b);break;
case '*':printf("%d\n",a*b);break;
case '%': if(b == 0) printf("error\n");
else printf("%d\n",a%b);break;
case '/': if(b == 0) printf("error\n");
else printf("%d\n",a/b);break;
}
}
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发