C语言程序设计 入门源代码代码集合

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

演示1#includestdio.hvoidprint_star(void){printf(*****************\n);}voidprint_welcome(void){printf(Clanguage,welcome!\n);}voidmain(){print_star();print_welcome();print_star();getchar();}演示2#includestdio.hintsum(inti,intj){return(i+j);}voidmain(){intn1,n2;printf(input2numbers:\n);scanf(%d%d,&n1,&n2);printf(thesum=%d\n,sum(n1,n2));getchar();}演示3#includestdio.hintmaxnum(int,int,int);main(){inta,b,c;printf(Pleaseenter3numbers:\n);scanf(%d,%d,%d,&a,&b,&c);printf(Maxnumis%d\n,maxnum(a,b,c));return0;}intmaxnum(intx,inty,intz){intmax=x;if(ymax)max=y;if(zmax)max=z;returnmax;}演示4#includestdio.hints1(intn){intj,s;s=0;for(j=1;j=n;j++)s=s+j;returns;}intsum(intn){inti,s=0;for(i=1;i=n;i++)s=s+s1(i);returns;}voidmain(){intn;printf(n:);scanf(%d,&n);printf(s=%d\n,sum(n));}演示5#includestdio.hvoidfunc(intn){inti;for(i=n-1;i=1;i--)n=n+i;printf(n=%d\n,n);}voidmain(){intn;printf(Inputn:);scanf(%d,&n);func(n);printf(n=%d\n,n);}演示6#includestdio.hvoidswap(inta,intb){inttemp;temp=a;a=b;b=temp;printf(swap:a=%d,b=%d\n,a,b);}voidmain(){inta,b;a=3;b=10;swap(a,b);printf(a=%d,b=%d\n,a,b);}演示7#includestdio.hintfunc(inta,intb){intc;c=a+b;returnc;}voidmain(){intx=6,y=7,z=8,r;r=func((x--,y++,x+y),z--);printf(%d\n,r);}演示8#includestdio.hmax(floatx,floaty){returnxy?x:y;}voidmain(){printf(%d\n,max(2,3.5));}演示9#includestdio.hintsum(intn){inti,s=0;for(i=0;i=n;i++)s=s+i;returns;}voidmain(){intm,sn;scanf(%d,&m);sn=sum(m);printf(thesumis%d\n,sn);}演示10#includestdio.hvoidswap(intx,inty);intmain(){inta,b;printf(input2numbers:\n);scanf(%d,%d,&a,&b);printf(inputnumberis:a=%d,b=%d\n,a,b);swap(a,b);printf(input2numbersis:a=%d,b=%d\n,a,b);return0;}voidswap(intx,inty){inttemp;temp=x;x=y;y=temp;printf(swapnumberis:x=%d,y=%d\n,x,y);}演示11#includestdio.h#defineK3#defineN5longf2(intn,intk){longpower=n;inti;for(i=1;ik;i++)power*=n;returnpower;}longf1(intn,intk){longsum=0;inti;for(i=1;i=n;i++)sum=sum+f2(i,k);returnsum;}intmain(void){printf(sumof%dpowerofintegerfrom1to%d=,K,N);printf(%ld\n,f1(N,K));return0;}演示12#includestdio.hintmin(inta,intb);intmain(void){intj,k,mininum;printf(input2integers:);scanf(%d,%d,&j,&k);mininum=min(j,k);printf(\nofthetwovalues%dand%d,themininumis%d\n,j,k,mininum);return0;}intmin(inta,intb){if(ab)returna;elsereturnb;}演示13#includestdio.hintfunc(inta,intb);voidmain(){intk=4,m=1,p;p=func(k,m);printf(%d\n,p);}intfunc(inta,intb){intm=0,i=2;i+=m+1;m=i+a+b;returnm;}演示14#includestdio.hintmax(intx,inty){intz;z=xy?x:y;returnz;}voidmain(){externintA,B;//声明外部变量printf(%d\n,max(A,B));}intA=13,B=-8;//定义外部变量演示15#includestdio.hintf1(intxb){externintxa;return(xa*xb);}intmain(void){externintxb;intxa=5;printf(xa=%d,xb=%d,result=%d,xa,xb,f1(xa));return0;}intxa=3,xb=4;演示16#includestdio.hvoidnum(){externintx,y;inta=15,b=10;x=a-b;y=a+b;}intx,y;voidmain(){inta=7,b=5;x=a+b;y=a-b;num();printf(%d,%d\n,x,y);}演示17#includestdio.hvoidmain(){voidswap();externinta,b;a=3;b=10;swap();printf(a=%d,b=%d\n,a,b);}inta,b;voidswap(){inttemp;temp=a;a=b;b=temp;}演示18#includestdio.hvoidauto_static(void){intvar_auto=0;staticintvar_static=0;printf(var_auto=%d,var_static=%d\n,var_auto++,var_static++);}voidmain(){inti;for(i=0;i3;i++)auto_static();}演示19#includestdio.hvoidswap(intx,inty){intt;t=x;x=y;y=t;}voidmain(){inta,b;scanf(%d,%d,&a,&b);swap(a,b);printf(%d,%d\n,a,b);}----------------------------------------------------------------------------------------------------------#includestdio.hintx,y;voidswap(int,,int){intt;t=x;x=y;y=t;}voidmain(){scanf(%d,%d,&x,&y);swap(x,y);printf(%d,%d\n,x,y);}#includestdio.hintx,y;voidswap(intx,inty){intt;t=x;x=y;y=t;}voidmain(){scanf(%d,%d,&x,&y);swap(x,y);printf(%d,%d\n,x,y);}----------------------------------------------------------------------------------------------------------------------演示20#includestdio.hintfac(intn){staticintf=1;f=f*n;returnf;}voidmain(){inti;for(i=1;i=5;i++)printf(%d!=%d\n,i,fac(i));}演示21#includestdio.hintmain(void){inta=2;intp=a;printf(%d\n,a);{inta=7;printf(%d\n,a);printf(%d\n,p);}printf(%d\n,++a);return0;}演示22#includestdio.hintfunc(inta,intb);voidmain(){intk=4,m=1,p;p=func(k,m);printf(%d,,p);p=func(k,m);printf(%d\n,p);}intfunc(inta,intb){staticintm=0,i=2;i+=m+1;m=i+a+b;returnm;}演示23#includestdio.hf(intn){intc;if(n==6)c=1;elsec=(f(n+1)+1)*2;returnc;}voidmain(){printf(%d\n,f(1));}演示24#includestdio.hlongpower(intn){longf;if(n1)f=power(n-1)*n;elsef=1;returnf;}main(){intn;longx;printf(inputanintegernumber:\n);scanf(%d,&n);x=power(n);printf(%d!=%ld\n,n,x);getchar();}演示25#includestdio.hintfact(){staticinti=5;if(i==0)return1;else{i--;return(i+1)*fact();}}voidmain(){printf(fact=%d\n,fact());}演示26#includestdio.hintfun(intk);intw=3;voidmain(){intw=10;printf(%d\n,fun(5)*w);}intfun(intk){if(k==0)returnw;return(fun(k-1)*k);}演示27#includestdio.hintfac(intn){registerinti,f=1;for(i=1;i=n;i++)f=f*i;returnf;}main(){inti;for(i=1;i=5;i++)printf(%d!=%d\n,i,fac(i));}演示28#includestdio.hage(intn){intc;if(n==1)c=10;elsec=age(n-1)+2;returnc;}voidmain(){printf(%d\n,age(5));}演示29#includestdio.

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功