帮忙做几个C语言的题啊,感激不尽!

2025-04-23 22:56:03
推荐回答(1个)
回答1:

8. 设a=13,n=7,计算下面表达式的值
(1)a+=3*a a=13+39=52
(2) a-=2 a=13-2=11
(3) a*=10-3 a=13*7=91
(4) a/=(a+a)/2 a= 13/(26/2) = 1
(5) a%=(n%=2) a= 13%(7%2) = 13%1 = 0
(6) a+=a-=a*=a a=13*13 = 169, a= 169-169 = 0, a = 0+0 = 0
以上结果全部是运行所得的

9. 指出下列程序中的错误之处
原程序里有多个错误, 修改如下:
#define taxofrate 0.06; //常量名中间不能有空格
main()
{float cost,total,shipping; //少了定义
printf("Enter the cost of the item:");
scanf("%f",&cost); // 错误: scanf("%f",&cost);
printf("Enter the shipping charge:");
scanf("%f/n",&shipping);
total=cost+cost*taxofrate + shipping;
printf("the total is %f:",total); //%f 而不是 &f
}

5. 编一程序,从键盘输入一个5位正整数,然后分别求出它的个位数,十位数,百位数,千位数和万位数,并打印出这五位数字的和。如输入12345,打印出15(1+2+3+4+5=15)
main()
{
int a,b,c,d,e,f,t;
scanf("%d", &t);
a=t/10000;
b=(t-a*10000)/1000;
c=(t-a*10000-b*1000)/100;
d=(t-a*10000-b*1000-c*100)/10;
e=t%10;
f=a+b+c+d+e;
cout< cout< cout< cout< cout< cout<}

6. 求下面算术表达式的值:
(1) x+a%3*(int)(x+y)%2/4-6,设x=2.8,a=7,y=4.6 -3.2
(2) (double)(a+b)/3+(int)x%(int)y,设a+8,b=2,x=13.5,y=10.5 6.3333

7. 写出程序运行结果
10, 9, 20, 10