C語言程序設(shè)計(jì)入門源代碼代碼集合_第1頁
C語言程序設(shè)計(jì)入門源代碼代碼集合_第2頁
C語言程序設(shè)計(jì)入門源代碼代碼集合_第3頁
C語言程序設(shè)計(jì)入門源代碼代碼集合_第4頁
C語言程序設(shè)計(jì)入門源代碼代碼集合_第5頁
已閱讀5頁,還剩9頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

#inelude<>voidprint_star(void){voidprint_welcome(void){printf("***************printf("***************printf("CIanguage,welcome!\n");}voidmain(){print_star();print_welcome();print_star();getchar();}演示2#include""intsum(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#include""intmaxnum(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(y>max)max=y;if(z>max)max=z;returnmax;}演示4#inelude<>ints1(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#inelude<>voidfunc(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\in",n);}演示6#inelude<>voidswap(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#inelude<>intfunc(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#include<>max(floatx,floaty){returnx>yx:y;}voidmain(){printf("%d\n",max(2,);}演示9#include<>intsum(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#include<>voidswap(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#include""#defineK3#defineN5longf2(intn,intk){longpower=n;inti;for(i=1;i<k;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#inelude<>intmin(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(a<b)returna;elsereturnb;}演示13#include<>intfunc(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#include<>intmax(intx,inty){int乙z=x>yx:y;return乙}voidmain(){externintA,B;II 聲明外部變量printf("%d\n",max(A,B));}intA=13,B=-8;II 定義外部變量演示15#inelude<>intf1(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#inelude<>voidnum(){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#inelude<>voidmain(){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#inelude<>voidauto_statie(void){intvar_auto=0;staticintvar_statie=0;printf("var_auto=%d,var_statie=%d\n",var_auto++,var_static++);}voidmain(){inti;for(i=0;i<3;i++)auto_statie();}演示19#inelude<>voidswap(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);#inelude<>intx,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);}#inelude<>intx,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#inelude<>intfac(intn){staticintf=1;f=f*n;returnf;}voidmain(){inti;for(i=1;i<=5;i++)printf("%d!=%d\n",i,fac(i));演示21#include""intmain(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#include<>intfunc(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#include<>f(intn){elsec=(f(n+1)+1)*2;returnc;}voidmain(){printf("%d\n",f(1));}演示24#include<>longpower(intn){longf;if(n>1)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#include<>intfact(){staticinti=5;if(i==0)return1;else{i--;return(i+1)*fact();voidmain(){printf("fact=%d\n",fact());}演示26#inelude<>intfun(intk);intw=3;voidmain(){intw=10;printf("%d\n",fun(5)*w);}intfun(intk){if(k==0)returnw;return(fun(k_1)*k);}演示27#inelude<>intfac(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#include<>age(intn){elsec=age(n_1)+2;returnc;}voidmain(){printf("%d\n",age(5));}演示29#include<>#definePI#definecircuit(r)2*PI*r#definearea(r)PI*r*rvoidmain(){floatra,c,a;scanf("%f',&ra);c=circuit(ra);a=area(ra);printf("ra=%f,c=%f,a=%f",ra,c,a);}漢諾塔(演示30)#include""voidmove(int,char,char,char);intmain(void){intn;printf("inputndiskontowerA:\

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論