收藏 分享(赏)

计算机二级程序基础CMicrosoft+Word+文档.doc

上传人:dcjskn 文档编号:6414674 上传时间:2019-04-12 格式:DOC 页数:19 大小:91KB
下载 相关 举报
计算机二级程序基础CMicrosoft+Word+文档.doc_第1页
第1页 / 共19页
计算机二级程序基础CMicrosoft+Word+文档.doc_第2页
第2页 / 共19页
计算机二级程序基础CMicrosoft+Word+文档.doc_第3页
第3页 / 共19页
计算机二级程序基础CMicrosoft+Word+文档.doc_第4页
第4页 / 共19页
计算机二级程序基础CMicrosoft+Word+文档.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

1、01#include void main()int a,b,c,s;a=8;b=12,c=6;s=a+b*c;printf(“s=%dn“,s);02auto break case char continue default dodouble else enum extern float for goto ifint long register return short signed sizeof staticstruct switch typedef union unsigned void volatile while03#include void main() int x,y,z,w;un

2、signed int k;x=10;y=-20;k=30;z=x+k;w=y+k;printf(“x+k=%d,y+k=%dn“,z,w);04#include void main()char c1,c2;c1=a;c2=b;c1=c1-32;c2=c2-32;printf(“%c,%cn“,c1,c2);05#include void main()int x=1,y=2;int x=2;int x=3;printf(“x=%d,y=%dn“,x,y);printf(“x=%d,y=%dn“,x,y);printf(“x=%d,y=%dn“,x,y);06#include void main(

3、)int i=97;char ch=a; putchar(i);putchar(n);putchar(ch);putchar(n);07#include void main()int ch;ch=getchar();putchar(ch);putchar(n);08#include void main()float r,l,s;scanf(“%f“,l=2*3.14159*r;s=3.14159*r*r;printf(“nl=%8.4f“,l);printf(“ns=%8.4fn“,s);09#include void main() float r;scanf(“%f“,printf(“nl=

4、%8.4f“,2*3.14159*r);printf(“ns=%8.4fn“,3.14159*r*r);10#include void main() char ch1,ch2,ch3;ch1=getchar();ch2=getchar();ch3=getchar();putchar(ch3);putchar(n);putchar(ch2);putchar(n);putchar(ch1);putchar(n);11#include void main() char ch1,ch2,ch3;scanf(“%c%c%c“,printf(“%c,%dn“,ch3,ch3);printf(“%c,%dn

5、“,ch2,ch2);printf(“%c,%dn“,ch1,ch1);12#include void main() int num1,num2,num3;float average;printf(“Please input thren numbers:n“);scanf(“%d,%d,%d“,average=(num1+num2+num3)/3.0;printf(“average=%7.2fn“,average);13#include #include void main() float a,b,c,disc,x1,x2;printf(“Please input a,b,c:n“);scan

6、f(“%f,%f,%f“,disc=b*b-4*a*c;if(disc0)|(disc=0)x1=(-b+sqrt(disc)/(2*a);x2=(-b-sqrt(disc)/(2*a);printf(“nx1=%6.2fnx2=%6.2fn“,x1,x2);elseprintf(“This is wrong!n“);14#include #include void main() char a; printf(“Please input a lowercase letter:n“);a=getchar();a=a-32;printf(“%cn“,a);15#include void main(

7、)int a1=1,a2=0,a3=2;printf(“%dn,%dn,%dn,“,a1,a1+a2+a3,a3-a1);16#include #include void main()double x;scanf(“%lf“,if(x=0)printf(“%10.6lfn“,sqrt(x);elseprintf(“That is wrong!n“);17#include #include void main()double x;scanf(“%lf“,if(x=0)printf(“%10.6fn“,sqrt(x);elseprintf(“Enter data error!n“);18#incl

8、ude void main()float a,b;scanf(“%f,%f“,if(ab) printf(“%fn“,a);else printf(“%fn“,b);19#include #include main()double x,y;scanf(“%lf“,if(xmain()double x,y;scanf(“%lf“,if(xvoid main()double x,y;printf(“please input x:n“);scanf(“%lf“,if(xvoid main()double x,y;printf(“please input x:n“);scanf(“%lf“,if(xv

9、oid main()double x,y;printf(“please input x:n“);scanf(“%lf“,if(xvoid main()int tall;char sex;printf(“input sex and tall:n“);scanf(“%c %d“,if(sex=F)if(tall=150)printf(“An“);else printf(“Bn“);else if(tall=170)printf(“An“);else printf(“Bn“);25#include void main()int i;printf(“Please input i:n“);scanf(“

10、%d“,switch(i)case 1:printf(“An“);case 2:printf(“Bn“);case 3:printf(“Cn“);case 4:printf(“Dn“);default:printf(“En“);26#include void main()int i;printf(“Please input i:n“);scanf(“%d“,switch(i)case 1:printf(“An“);break;case 2:printf(“Bn“);break;case 3:printf(“Cn“);break;case 4:printf(“Dn“);break;default

11、:printf(“En“);27#include void main()int i;printf(“Please input i:n“);scanf(“%d“,switch(i)case 1:case 2:case 3:printf(“ABCn“);break;case 4:printf(“Dn“);break;default:printf(“En“);28#include void main()int i;printf(“Please input i:n“);scanf(“%d“,switch(i)case 1:printf(“An“);case 2:printf(“Bn“);case 3:

12、printf(“Cn“);break;case 4:printf(“Dn“);break;default:printf(“En“);29#include void main()int score;scanf(“%d“,switch(score/10) case 10:case 9:printf(“%d:An“,score);break;case 8:case 7:printf(“%d:Bn“,score);break;case 6:printf(“%d:Cn“,score);break;default:printf(“%d:Dn“,score);30#include #include void

13、 main()int score;scanf(“%d“,switch(score/10) case 10:case 9:printf(“%d:An“,score);break;case 8:case 7:printf(“%d:Bn“,score);break;case 6:printf(“%d:Cn“,score);break;default:printf(“%d:Dn“,score);31#include #include void main()float a,b,c,x1,x2,disc;printf(“input a,b,c:n“);scanf(“%f %f %f“,if(fabs(av

14、oid main()unsigned int year,leap;printf(“Enter year:n“);scanf(“%d“,if(year%400=0)leap=1;elseif(year%4=0else leap=0;if(leap=1)printf(“%d:is a leap year.n“,year);else printf(“%d is not a leap year.n“,year);33#include void main()int a,b;char c;scanf(“%d%c%d“,switch(c)case+:printf(“a+b=%dn“,a+b);break;c

15、ase-:printf(“a-b=%dn“,a-b);break;case*:printf(“a*b=%dn“,a*b);break;case/:if(b!=0) printf(“a/b=%dn“,a/b);else printf(“b=0n“);break;case%:if(b!=0) printf(“a mod b=%dn“,a%b);else printf(“b=0n“);break;default:printf(“Data out of rangen“);34#include void main()int a=25,b=14,c=19;if(avoid main()int i=1,j;

16、switch(i)case 1:for(j=0;jvoid main()int a,b,x,y;scanf(“%d%dn“,if(ab)printf(“*y=%dn“,y);else printf(“*x=%dn“,x);36#include void main()int a,t,m;scanf(“%d“,t=a/10;switch(t)case 0:case 1:case 2:printf(“m=1n“);break;case 3:printf(“m=2n“);break;case 4:printf(“m=3n“);break;case 5:printf(“m=4n“);break;defa

17、ult:printf(“m=5n“);37#include void main()int x,y;scanf(“%d“,if(-5void main()int s=0,i;for(i=1;ivoid main()int i,n;long fac;scanf(“%d“,fac=1;for(i=1;ivoid main()int i,j;for(i=1,j=10;i#include void main()char ch;for(;)ch=getch();if(ch=27)break;if(ch=13)continue;putch(ch);getch();42#include void main()

18、int i,j,N=5;for(i=1;ivoid main()int i,j,N=5;for(i=1;ivoid main()int i,j,N=5;for(i=1;ivoid main()int score;scanf(“%d“,while(score=0)switch (score/10)case 10:case 9:printf(“%d:An“,score);break;case 8:case 7:printf(“%d:Bn“,score);break;case 6:printf(“%d:Cn“,score);break;default:printf(“%d:Dn“,score);sc

19、anf(“%d“,46#include #include void main()double a,b;scanf(“%lf“,b=sin(a);printf(“%6.4lfn“,b);47#include #include void main()float x,y;int n;float power(float x,int n);scanf(“%f,%d“,y=power(x,n);printf(“%8.2fn“,y);float power(float x,int n)int i;float t=1;for(i=1;ilong fac(int k)long f=1;int i;for(i=1

20、;ivoid main()int a,b,m;int max(int,int);scanf(“%d,%d“,m=max(a,b);printf(“max=%dn“,m);int max(int x,int y)int t;if(xy)t=x;else t=y;return t;50#include int divisor(int a,int b)int r;dor=a%b;a=b;b=r;while(r!=0);return a;void main()int a,b,d;scanf(“%d,%d“,if(ab)d=divisor(a,b);elsed=divisor(b,a);printf(“

21、a=%d,b=%dn“,a,b);printf(“d=%dn“,d);51auto :声明自动变量 short :声明短整型变量或函数 int: 声明整型变量或函数long :声明长整型变量或函数 float:声明浮点型变量或函数 double :声明双精度变量或函数 char :声明字符型变量或函数 struct:声明结构体变量或函数 union:声明共用数据类型 enum :声明枚举类型 typedef:用以给数据类型取别名 const :声明只读变量 unsigned:声明无符号类型变量或函数 signed:声明有符号类型变量或函数 extern:声明变量是在其他文件正声明 regist

22、er:声明寄存器变量 static :声明静态变量 volatile:说明变量在程序执行中可被隐含地改变 void :声明函数无返回值或无参数,声明无类型指针 if:条件语句 else :条件语句否定分支(与 if 连用) switch :用于开关语句 case:开关语句分支 for:一种循环语句 do :循环语句的循环体 while :循环语句的循环条件 goto:无条件跳转语句 continue:结束当前循环,开始下一轮循环 break:跳出当前循环 default:开关语句中的“其他 ”分支 sizeof:计算数据类型长度 return :子程序返回语句(可以带参数,也可不带参数)循环条

23、件 52#include void main()int i,a5;for(i=0;i0)printf(“%4dn“,ai);53#define M 4#define N 4#include void main()int i,k;int aMN=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16;int bMN;for(i=0;ivoid main()int a5,k,*p;p=a;for(k=0;kstruct studentlong num;char name20;char sex;char addr40;a=3021103,“Jiang Linpan“,M,“Shaohan Road“;void main()printf(“No:%ldnName:%snSex:%cnAddress:%sn“,a.num,a.name,a.sex,a.addr);56#include void main()union exxint a,b;struct int c,d;lpp;e=10;e.b=e.a+20;e.lpp.c=e.a+e.b;e.lpp.d=e.a*e.b;printf(“%d,%dn“,e.lpp.c,e.lpp.d);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 网络科技 > 计算机原理

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报