資源描述:
《簡單c語言程序的例子》由會員上傳分享,免費在線閱讀,更多相關內容在應用文檔-天天文庫。
1、WORD資料下載可編輯例子:l#includemain(){tips();/*caller*/printf(“Successisaboutbangingonafterothershaveletgo”);}tips()/*caller*/{printf(“Whenyoureachtheendoftheropetieaknot&hangon”,)0;}[上述程序的輸出結果如下:Whenyoureachtheendoftheropttieaknot&hangon.Successisabouthangingonafterothers
2、haveletgo.]l#includemain(){inta,fact;printf(“Enteranynumber”);scanf(“%d”,&a);fact=rec(a);printf(“Factorialvalueis%d”,fact);}rec(x);intx;{intf;if(x==1)return(1);elsef=x*rec(x-1);return(f);}[其顯示的結果為:Factorialvalueis2.]l比較兩個數較大的那個:#includemain()技術資料專業(yè)分享WORD資料下載
3、可編輯{inta,b,max;scanf(“%d%d”,&a,&b);if(a>b)max=a;elsemax=b;printf(“%d”,max);}l輸出a+b的值:#includevoidmain(){inta,b,x;scanf(“%d%d”,&a,&b);x=a+b;printf(“%d”,x);}l輸出a,b中最大的一位數:#includeintmax(intx,inty){intz;if(x>y)z=x;elsez=y;return(z);}voidmain(){inta,b,c;scanf(“%d%
4、d”,&a,&b);c=max(a,b);printf(“%d”,c);}l輸出Hello:#includeintmain(){printf(“Hello!”);技術資料專業(yè)分享WORD資料下載可編輯return0;}l求1~100的和:#includeintmain(){ints,n;s=0,n=1;A:s=s+n;n=n+1;if(n<=100)gotoA;printf(“%d”,s);}l請輸入一個三位數,將其各位逆序輸出:(如153,輸出351)#includevoidmain(){i
5、ntx,y,a,b,c;printf("請輸入一個三位數的數:");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;y=c*100+b*10+a;printf("%d",y);}#includevoidmain(){intx,a,b,c,d;printf("請輸入一個三位數的數:");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;d=c*100+b*10+a;printf("%d",d);}買雞:技術資料專業(yè)分享WORD資料下載可編輯#include<
6、stdio.h>voidmain(){intx,y,z;if(x>=0&&x<=19,y>=0&&y<=33,z>=0&&z<=100)while(x=19){x=0;5*x+3*y+z/3==100&&x+y+z==100;x=x+1;}printf("%d%d%d",x,y,z);}y==(100-5*x-z/3)/3&&y==100-x-z;z==(100-5*x-3*y)*3&&z==100-x-y;#includevoidmain(){intx=0,y,z;while(x<=19){5*x+3*y+z/3==100&&x+
7、y+z==100;x=x+1;printf("%d%d%d",x,y,z);}}#includevoidmain(){intx=0,y=0,z=0;while(x<=19){while(y<=33){while(z<=100){技術資料專業(yè)分享WORD資料下載可編輯z==(100-5*x-3*y)*3&&z==100-x-y;z=z+1;printf("%dt",z);}y==(100-5*x-z/3)/3&&y==100-x-z;y=y+1;printf("%dt",y);}x=x+1;printf("%dt",x);}}l
8、計算x=20+3(x-1):#includevoidmain(){intage(intx)