资源描述:
《c语言考前复习资料,很好的例题》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、计算类题:124+456=780#includeintmain(){inta,b,sum;a=124;b=456;sum=a+b;printf("sum=%d",sum);return0;}计算a*b的值#includeintmain(){inta,b,c;scanf("%d%d",&a,&b);c=a*b;printf("c=%d",c);return0;}两个数的比较类的函数:abmax(3,5)#includeintmain(){intmax(
2、intx,inty);inta,b,c;scanf("%d,%d",&a,&b);c=max(a,b);printf("c=%d",c);return0;}intmax(intx,inty){intz;if(x>y)z=x;elsez=y;return(z);}三个数的比较:max(a,b,c);#includeintmain(){intmax(intx,inty,intz);inta,b,c,d;scanf("%d,%d,%d",&a,&b,&c);d=max(a,b,c);printf("d=
3、%d",d);return0;}intmax(intx,inty,intz){intm;if(x>y&&x>z)m=x;{elseif(y>x&&y>z)m=y;}elsem=z;return(m);}计算5!当型循环计算(写好)#includeintmain(){inti,t;t=1;i=2;while(i<=12){t=t*i;i++;}printf("jieguo=%d",t);return0;}计算当型计算1+1/2-1/3+1/4'----+1/99+1/100(还没写好)#incl
4、udeintmain(){intsign=1;doubledeno=2.0,sum=1.0,term;while(deno<=100){sign=-sign;term=sign/deno;deno=deno+1;sum=sum=term;}printf("%f",sum);return0;}计算公式类的计算题:c=(5.o/9)*(f-32);#includeintmain(){floatf,c;scanf("%d",&f);c=(5.0/9)*(f-32);printf("
5、c=%d",c);return0;}F=64.0计算c的值:#includeintmain(){floatf,c;f=64.0;c=(5.0/9)*(f-32);printf("f=%fc=%f",f,c);return0;}计算某一年是否为闰年?(用if的选择句)#includeintmain(){intyear,leap;printf("enteryear:");scanf("%d",&year);if(year%4==0){if(year%100==0){if(ye
6、ar%400==0)leap=1;elseleap=0;}elseleap=1;}elseleap=0;if(leap)printf("%dis",year);elseprintf("%disnot",year);printf("aleapyear.");return0;}逻辑函数表达闰年的方法:#includeintmain(){intyear,leap;printf("enteryear:");scanf("%d",&year);if((year%4==0&&year%100!=0)
7、
8、(ye
9、ar%400==0))leap=1;elseleap=0;if(leap)printf("%dis",year);elseprintf("%disnot",year);printf("aleapyear.");return0;}找出三个数中间的最大值:abc(还有处错误)#includeintmain(){inta,b,c;scanf("%d%d%d",&a,&b,&c);if(a>b&&a>c)printf("max=%d",a);elseif(b>a&&b>c)printf("max=
10、%d",b);elseprintf("max=%d",c);return0;}计算1+2.。。。+100的结果:#includeintmain(){inti=1,sum=0;while(i<=100){sum=sum+i;i=i+1;}printf("你想要的结果sum=%d",sum);return