C语言程序设计苏小红版答案(24页).doc
《C语言程序设计苏小红版答案(24页).doc》由会员分享,可在线阅读,更多相关《C语言程序设计苏小红版答案(24页).doc(24页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-C语言程序设计苏小红版答案-第 24 页2.2 #includemain()float x=2.5,y=2.5,z=2.5;printf(x=%fn,x);printf(y=%fn,y);printf(z=%fn,z);3.1(1) #includemain()int a=12,b=3;float x=18.5,y=4.6;printf(%dn,(float)(a*b)/2);printf(%dn,(int)x%(int)y);3.2 #includemain()int x,b0,b1,b2,s;printf(Inputx:);scanf(%d,&x);b2=x/100;b1=(x-b2*1
2、00)/10;b0=x%10;s=b0*100+b1*10+b2;printf(s=%dn,s);3.3 #include#includemain()float rate=0.0225;float n,capital,deposit;printf(Input n,capital:);scanf(%f,%f,&n,&capital);deposit=capital*pow(1+rate,n);printf(deposit=%fn,deposit);3.4 #include#includemain()float a,b,c;double x,y;printf(Inputa,b,c:);scanf(
3、%f,%f,%f,&a,&b,&c);x=(-b+sqrt(b*b-4*a*c)/(2*a);y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);4.1(1) #includemain()char c1=a,c2=b,c3=c;printf(a%cb%cc%cn,c1,c2,c3);4.1(2) #includemain()int a=12,b=15;printf(a=%d%,b=%d%n,a,b);4.1(3) #includemain()int a,b;scanf(%2d%*2s%2d,&a,&b);printf(%d,%dn,a,b);4
4、.2 #includemain()long a,b;float x,y;scanf(%d,%dn,&a,&b);scanf(%f,%fn,&x,&y);printf(a=%d,b=%dn,a,b);printf(x=%f,b=%fn,x,y);5.1 #includemain()float a;printf(Innputa:);scanf(%f,&a);if(a=0)a=a;printf(a=%fn,a);elsea=-a;printf(a=%fn,a);5.2 #includemain()int a;printf(Inputa:);scanf(%d,&a);if(a%2=0)printf(a
5、是偶数);elseprintf(a是奇数);5.3 #include#includemain()float a,b,c,s,area;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&b,&c);if(a+bc&a+cb&b+ca)s=(a+b+c)/2;area=(float)sqrt(s*(s-a)*(s-b)*(s-c);printf(area=%fn,area);elseprintf(不是三角形);5.4 #include#includemain()float a,b,c,x,y;printf(Inputa,b,c:);scanf(%f,%f,%f,&a,&
6、b,&c);if(a=0)printf(该方程不是一元二次方程n);if(b*b-4*a*c0)x=(-b+sqrt(b*b-4*a*c)/(2*a); y=(-b-sqrt(b*b-4*a*c)/(2*a);printf(x=%f,y=%fn,x,y);else if(b*b-4*a*c=0)x=-b/(2*a); y=-b/(2*a);printf(x=%f,y=%fn,x,y);elseprintf(该方程无实根n);5.5 #includemain()int year,flag;printf(Input a year:);scanf(%d,&year);if(year%4=0&year
7、%400!=0|year%400=0)flag=1;elseflag=0;if(flag=1)printf(%d is a leap year !n,year);elseprintf(%d is not a leap year !n,year);5.6 #includemain()int year,flag;printf(Input a year:);scanf(%d,&year);flag=year%400=0|year%4=0&year%100!=0?1:0;if(flag=1&flag!=0)printf(%d is a leap year !n,year); elseprintf(%d
8、 is not a leap year !n,year);5.7 #includemain()char ch;printf(Inputch:);scanf(%c,&ch);if(ch=a&ch=A&ch=Z)ch=getchar();ch=ch+32;printf(%c,%dn,ch,ch);elseprintf(%c,ch);5.8 #includemain()char ch;printf(Inputch:);scanf(%c,&ch);if(ch=48&ch=65&ch=97&ch=122)printf(ch是小写字母n); else if(ch=32)printf(ch是空格n);els
9、e printf(ch是其他字符n);5.9 #includemain()int score,grade;printf(Input score:);scanf(%d,&score);grade=score/10;if(score100) printf(Input errorn); if(score=90&score=80&score=70&score=60&score=0&score60)printf(%d- -En,score);5.10 #includemain()int year,month;printf(Input year,month:);scanf(%d,%d,&year,&mon
10、th); if(month12|month=0)printf(error monthn); else switch(year,month)case 12:case 10:case 8:case 7:case 5:case 3:case 1:printf(31天n);break;case 11:case 9:case 6:case 4:printf(30天n); break;case 2:if(year%4=0&year!=0|year%400=0)printf(29天n);elseprintf(28天n); break; default: printf(Input errorn);6.1(1)
11、 #includemain()int i,j,k;char space= ;for(i=1;i=4;i+)for(j=1;j=i;j+)printf(%c,space);for(k=1;k=6;k+)printf(*);printf(n);6.1(2) #includemain()int k=4,n;for(n=0;nk;n+)if(n%2=0) continue;k-;printf(k=%dn,n=%dn,k,n);6.1(3) #includemain()int k=4,n;for(n=0;nk;n+)if(n%2=0) break;k-;printf(k=%d,n=%dn,k,n);6.
12、2(1) #includemain()int i,sum=0;for(i=1;i=101;i+)sum=sum+i;printf(sum=%dn,sum);6.2(2) #includemain()long i;long term,sum=0;for(i=1;i=101;i=i+2)term=i*(i+1)*(i+2);sum=sum+term;printf(sum=%ldn,sum);6.2(4) #include#includemain()int n=1;float term=1.0,sign=1,sum=0;while(term=1e-4)term=1.0/sign;sum=sum+te
13、rm;sign=sign+n;n+;printf(sum=%fn,sum);6.2(5) #include#includemain()int n=1,count=1;float x;double sum,term;printf(Input x:);scanf(%f,&x);sum=x;term=x;doterm=-term*x*x/(n+1)*(n+2); sum=sum+term;n=n+2;count+;while(fabs(term)=1e-5);printf(sin(x)=%f,count=%dn,sum,count);6.3 #includemain()int x=1,find=0;
14、 while(!find)if(x%2=1&x%3=2&x%5=4&x%6=5&x%7=0)printf(x=%dn,x);find=1;x+;/*int x,find=0;for (x=1;!find;x+)if(x%2=1&x%3=2&x%5=4&x%6=5&x%7=0)printf(x=%dn,x);find=1;6.4 #includemain()int i,n;long p=1,m=1;printf(Input n:);scanf(%d,&n);for(i=1;i=n;i+)p=i*i;m=i*i*i;printf(p=%d,m=%dn,i,p,i,m);6.5 #includema
15、in()float c,f;for(c=-40;c=110;c=c+10)f=9/5*c+32;printf(f=%fn,f);6.6 #include#includemain()int n;double c=0.01875,x;dox=x*pow(1+c,12)-1000;n+;while(x0);printf(x=%dn,x);6.7 #includemain()int n=0;float a=100.0,c;printf(Inputc:);scanf(%f,&c);doa=a*(1+c);n+;while(a=200);printf(n=%dn,n);6.8 #include#inclu
16、demain()int n=1,count=1;double sum=1,term=1;while(fabs(term)=1e-5)term=pow(-1,count)*(1.0/(n+2);sum=sum+term;n=n+2;count+; sum=4*sum;printf(sum=%f,count=%dn,sum,count);6.9 #include#includemain()int n=1,count=1;double sum=1,term=1;while(fabs(term)=1e-5)term=term*(1.0/n);sum=sum+term; n+;count+;printf
17、(sum=%f,count=%dn,sum,count);6.10 #include#includemain()int x;for(x=100;x=999;x+)if(x=pow(x/100,3)+pow(x/10%10,3)+pow(x%10,3)printf(x=%dn,x);6.11 #includemain()int i=0,n;long sum=0,term=1;printf(Inputn:);scanf(%d,&n);doi+;term=term*i;sum=sum+term;while(sumn);printf(%dn,i-1);6.12 #includemain()int i,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言程序设计 苏小红版 答案 24
限制150内