资源预览内容
第1页 / 共69页
第2页 / 共69页
第3页 / 共69页
第4页 / 共69页
第5页 / 共69页
第6页 / 共69页
第7页 / 共69页
第8页 / 共69页
第9页 / 共69页
第10页 / 共69页
亲,该文档总共69页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
.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*100)/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(%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.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是偶数);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,&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%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 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);else 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,&month); 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) #includemain()int i,j,k;char space= ;for(i=1;i=4;i+)
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号