资源描述:
《安阳工学院11级计科系c语言考试题参考答案》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、安阳工学院11级计科系c语言考试题参考答案//1函数求值#include"stdio.h"intmain(){intx,y;printf("Pleaseenterx:");scanf("%d",&x);printf("x=%d",x);if(x<0
2、
3、x>100)y=-1;elseif(x=0)y=0;elsey=1;printf("y=%d",y);return0;}//2.3个数排列顺序#include"stdio.h"intmain(){floata,b,c,t;printf("pleasea,b,c
4、(并用空格隔开):");scanf("%f%f%f",&a,&b,&c);printf("比较前a=%.2fb=%.2fc=%.2f",a,b,c);printf("");if(a
5、a,floatb,floatc,floatd);floatmin(floata,floatb,floatc,floatd);floata,b,c,d,Max,Min;printf("pleaseentera,b,c,d:");scanf("%f%f%f%f",&a,&b,&c,&d);printf("a=%.2f,b=%.2f,c=%.2f,d=%.2f",a,b,c,d);Max=max(a,b,c,d);Min=min(a,b,c,d);printf("max=%.2fmin=%.2f",Max,M
6、in);return0;}floatmax(floata,floatb,floatc,floatd){floatm;floatmax(floata,floatb);m=max(a,b);m=max(m,c);m=max(m,d);returnm;}floatmax(floata,floatb){if(a>=b)returna;elsereturnb;}floatmin(floata,floatb,floatc,floatd){floatm;floatmin(floata,floatb);m=min(a,b);m=m
7、in(m,c);m=min(m,d);returnm;}floatmin(floata,floatb){if(a<=b)returna;elsereturnb;}//4.成绩等级#include"stdio.h"intmain(){intscore,k;printf("pleaseenteryourscore:");scanf("%d",&score);k=score/10;switch(k){case9:printf("成绩等级:A");break;case8:printf("成绩等级:B");break
8、;case7:printf("成绩等级:C");break;case6:printf("成绩等级:D");break;case5:case4:case3:case2:case1:case0:printf("成绩等级:E");break;default:printf("error!");}return0;}//5.求函数值#include"stdio.h"intmain(){floatx,y;printf("pleaseenterx:");scanf("%f",&x);printf("x=%.2f
9、",x);if(x<1.00)y=x;if(x==10)y=3*x-11;if(x>=1&&x<0
10、
11、x>10)y=2*x-1;printf("y=%.2f",y);return0;}//6.求300到400全部素数#include"stdio.h"#include"math.h"intmain(){inti,j=0,k,n=0;for(n=301;n<=400;n=n+2){k=sqrt(n);for(i=2;i<=k;i++)if(n%i==0)break;if(i>=k+1){printf("%5d",n
12、);j++;}if(j==5){printf("");j=0;}}printf("");return0;}//7.输出前Fibonacci数列20项#include"stdio.h"intmain(){intf1,f2,f3;inti;intj=2;//前两项不用参与变换,直接赋初值为2;f1=1;f2=1;printf("%12d%12d",f1,