2、io.h>main(){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比較兩個數(shù)較大的那個:#includemain()專業(yè)知識整理分享WORD格式可編輯{inta,b,max;scanf(“%d%d”,&a,&b);if(a>b)max=a;
3、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中最大的一位數(shù):#includeintmax(intx,inty){intz;if(x>y)z=x;elsez=y;return(z);}voidmain(){inta,b,c;scanf(“%d%d”,&a,&b);c=max(a,b);printf(“%d”,c);}l輸出Hello:#includeintma
4、in(){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請輸入一個三位數(shù),將其各位逆序輸出:(如153,輸出351)#includevoidmain(){intx,y,a,b,c;printf("請輸入一個三位數(shù)的數(shù):");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;y=c*100+b*10+a;prin
5、tf("%d",y);}#includevoidmain(){intx,a,b,c,d;printf("請輸入一個三位數(shù)的數(shù):");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;d=c*100+b*10+a;printf("%d",d);}買雞:專業(yè)知識整理分享WORD格式可編輯#includevoidmain(){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
6、;}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+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格式可編輯
7、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計算x=20+3(x-1):#includevoidmain(){intage(intx)inti,j;sca