您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > C语言程序设计源代码
C语言程序设计讲稿中的源程序第一章C1_301.Cmain(){intn,p;for(n=1;;n++){p=n*n+n+41;printf(%d,p=%d,n,p);if(s(p)==0)printf(ok\n);else{printf(error.\n);break;}}}s(v)intv;{intj;if(v2)return(-1);for(j=2;jv;j++)if(v%j==0)return(-1);return(0);}第二章C201.Cmain(){inti=32767;printf(\ni=%d,i+1);getch();}C202.Cmain(){longinti;i=1;printf(\n1!=%d,i);i=2*i;printf(\n2!=%d,i);i=3*i;printf(\n3!=%d,i);i=4*i;printf(\n4!=%d,i);i=5*i;printf(\n5!=%d,i);i=6*i;printf(\n6!=%d,i);i=7*i;printf(\n7!=%d,i);i=8*i;printf(\n8!=%d,i);i=9*i;printf(\n9!=%d,i);i=10*i;printf(\n10!=%d,i);getch();}C203.Cmain(){floata=1.2345678,b=1.12345670;printf(\n\na==%12.10f,a);printf(\nb==%12.10f,b);getch();}C204.Cmain(){chara,b,c,d,e,f;a='\5';b='\60';c='\101';d='\xe';e='\x41';printf(a=%cb=%cc=%cd=%ce=%c\n,a,b,c,d,e);getch();}C2_301.Cmain(){inti=2,j=1,k;k=i+++++j;printf(\n\ni=%dj=%dk=%d\n,i,j,k);getch();printf(\n\1011);getch();}第三章C3_401.C#includestdio.hmain(){chara='A';printf(%c\n,putchar(a));getch();}C3_402.C#includestdio.hmain(){chara[]=abcdef;printf(%c\n,puts(a));getch();}C3_403.Cmain(){inti=12;floatx=1.3;printf(\n%4d\n%-4d\n%10.5f\n%-10.5f,i,i,x,x);getch();}C3_404.Cmain(){inti=12;floatx=1.3;printf(\n%4d\n%04d\n%10.5f\n%010.5f,i,i,x,x);getch();}C3_405.Cmain(){chars[]=ABC;printf(\n%s\n%5.3s,s,s);getch();}C3_406.Cmain(){inti=123;longj=123456789;floatx=1.1234567890;doubley=1.1234567890;printf(\n%d\n%ld\n%12.10f\n%12.10lf,i,j,x,y);getch();}C3_407.Cmain(){inta=567;charc=65;chars[]=ABC;floatx=567.789;printf(\n%d\n%x\n%o\n%u,a,a,a,a);printf(\n%c\n%s,c,s);printf(\n%f\n%e\n%g,x,x,x);getch();}C3_408.C#includestdio.hmain(){charc;inti;for(i=1;(c=getchar())!='\n';i++)printf(\nCharis%c.,c);getch();}C3_409.Cmain(){inta,b,c;scanf(%d%d%d,&a,&b,&c);printf(%d%d%d,a,b,c);getch();}C3_410.Cmain(){inti;floata;scanf(%5f%4d,&a,&i);printf(a=%fi=%d\n,a,i);getch();}C3_411.Cmain(){inti,j;printf(\n1:%d,printf(\n2:%d,scanf(%d%d,&i,&j)));getch();}C3_412.C#includestdio.hmain(){charc;while((c=getch())!=13){if(c=65&&c=90||c=97&&c=122){c=c+5;if(c90&&c97||c122)c=c-26;putchar(c);}}getch();}C3_601.C#defineprintt(x,y,z)printf(x=%d,y=%d,z=%d\n,x,y,z)main(){intx,y,z;x=y=z=2;++x||++y&&++z;printt(x,y,z);x=y=z=2;++x&&++y||++z;printt(x,y,z);x=y=z=2;++x&&++y&&++z;printt(x,y,z);x=y=z=-2;++x||++y&&++z;printt(x,y,z);x=y=z=-2;++x&&++y||++z;printt(x,y,z);x=y=z=-2;++x&&++y&&++z;printt(x,y,z);}C3_602.C#definePRINT(x)printf(%d\n,x)#includestdio.hmain(){intx=1,y=1,z=0;x=x&&y||z;PRINT(x);PRINT(x||!y++&&++z);PRINT(y);PRINT(z);x=y=1;z=x++-1;PRINT(x);PRINT(z);z+=-x+++++y;PRINT(x);PRINT(z);PRINT(y);}C3_603.C#definePRINT(X)printf(%d\n,X)#includestdio.hmain(){intx=3,y=2,z=1;x=y++=x&&x-y==++z;PRINT(x);PRINT(y);PRINT(z);y*=z=x+(z+2);PRINT(x);PRINT(y);PRINT(z);x=y=z=1;PRINT(--x&&++y||z++);PRINT(x);PRINT(y);PRINT(z);x=9;y=6;z=5;x=((x+y)%z=x%z+y%z)?1:0;PRINT(x);}第四章C4_101.Cincludestdio.hmain(){inta,b,max;printf(Inputaandb=);scanf(%d%d,&a,&b);if(ab)max=a;elsemax=b;printf(Themaxofaandb:%d\n,max);}C4_101B.C#includestdio.hmain(){inta,b,max;printf(Inputaandb=);scanf(%d%d,&a,&b);max=a;if(maxb)max=b;printf(Themaxofaandb:%d\n,max);}C4_103.C#includestdio.hmain(){intx,y;printf(EnterintegerXandY:);scanf(%d%d,&x,&y);if(x!=y)if(xy)printf(XY\n);elseprintf(XY\n);elseprintf(X=Y\n);}C4_105.C#includestdio.hmain(){charc;printf(Enteracharacter:);c=getch();if(c0x20)printf(\nIsacontrolcharacter.\n);elseif(c='0'&&c='9')printf(\nIsadigitcharacter.\n);elseif(c='A'&&c='Z')printf(\nIsacaptalcharacter.\n);elseif(c='a'&&c='z')printf(\nIsalowercharacter.\n);elseprintf(\nIsaothercharacter.\n);}C4_202.C#includestdio.hmain(){floatdata1,data2;charop;printf(Enteryourexpression:);scanf(%f%c%f,&data1,&op,&data2);switch(op){case'+':printf(%.2f+%.2f=%.2f\n,data1,data2,data1+data2);break;case'-':printf(%.2f-%.2f=%.2f\n,data1,data2,data1-data2);break;case'*':printf(%.2f*%.2f=%.2f\n,data1,data2,data1*data2);break;case'/':if(data2==0)printf(Divisionbyzero.\n);elseprintf(%.2f/%.2f=%.2f\n,data1,data2,data1/data2);break;default:printf(Unknownoperater.\n);}}第五章C5_101.Cmain(){inti,sum;i=1;sum=0;while(i=100){sum+=i;i++;}printf(Sum=%d\n,sum);printf(i=%d,i);getch();}C5_102.C#includestdio.hmain(){charch;while((ch=getche())!='a');}C5_201.Cmain(){inti,sum;i=1;sum=0;while(i=100){sum+=i;i++;}printf(Sum=%d\n,sum);printf(i=%d,i);getch();}C5_201B.Cmain(){inti,sum;i=1;sum=0;while(i=100)printf(i=%d,sum=%d\n,i,sum+=i);i++;printf(Sum=%d\n,sum);printf(i=%d,i);getch();}C5_201C.Cmain(){inti,sum;i=1;sum=0;while(i=100)sum+=i++;printf(\ni=%d,Sum=%d,i,sum);i=0;sum=0;while(++i=100)sum+=i;printf(\ni=%d,Sum=%d,i,sum);i=0;sum=0;while(i++100)sum+=i;printf(\ni=%d,Sum=%d,i,sum);i=0;sum=0;while(i100)sum+=++i;printf(\ni=%d,Sum=%d,i,sum);getch();}C5_202.C#includestdio.hmain(){charch;while((ch=getche())!='a');}C5_203.C#defineEOF-1#includestdio.hmain(){intc,nl=0,nc=0;while((c=getchar())!=EOF){++nc;if(c=='\n')++nl;}printf(chars=%d,lines=%d\n,nc,nl);}C5_301.Cmain(){unsignedintnumber;printf(\nInputthenumber:);scanf(%d,&number);do{printf(%d,number%10);number/=10;}while(number!=0);g
本文标题:C语言程序设计源代码
链接地址:https://www.777doc.com/doc-7289376 .html