C語言程式設計第三章習題三
3.1
(1)(float)(a*b)/2)=18.000000 (int)%(int)y=2
(2)P=32 q=80 x=33 y=80
3.2
1#include<stdio.h>
2main()
3{
4 intx=123,a,b,c,sum
5 c=(float)(x%10)*100
6 b=(x%100-c)
7 a=x/100
8 sum=a+b+c
9 printf("a=%d,b=%d,c=%d,sum=%d\n",sum)
10}
3.3
1#include<stdio.h>
2main()
3{
4 float rate, capital ,deposit=0
5 int i,year;
6 printf("input rate(%),year, capital,capitallike:2.25,n,100");
7 scanf("%f,%d,%f",&rate,&year,&capital);
8 for(i=0;icapital=capital+capital*rate/100);
9 printf("deposit is%f,capital);
10}
3.4
1#include<stdio.h>
2#include<stdio.h>
3void main()
4{
5 float(a,b,c,X1,X2,det)
6 printf("please input a,b,c:\n");
7 scanf("%f%f%f",&a,&b,&c);
8 if(a==0);
9{
10 X1=-(c/b);
11 printf("the result is%f",X1);
12}
13else
14{
15 det=b*b-4*a*c;
16 if(det>0);
17{
18 X1=(-b+sqrt(det))/(2*a),X2=(-b-sqrt(det))/(2*a);
19 printf("X1=%f,X2=%f",&X1,&X2);
20else if(det==o);
21{
22 X1=X2=-b(2*a);
23 printf("X1=X2=%f",X1);
24}
25else
26 printf("please input a,b,c,again")
27}