2、o.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);}[其顯示的結(jié)果為:Factorialvalueis2.]l比較兩個(gè)數(shù)較大的那個(gè):#includemain()....{inta,b,max;scanf(“%d%d”,&a,&b);if(a>b)max=a;elsemax
3、=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!”);....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請(qǐng)輸入一個(gè)三位數(shù),將其各位逆序輸出:(如153,輸出351)#includevoidmain(){intx,y,a,b,c;printf("請(qǐng)輸入一個(gè)三位數(shù)的數(shù):");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;y=c*100+b*10+a;printf("
5、%d",y);}#includevoidmain(){intx,a,b,c,d;printf("請(qǐng)輸入一個(gè)三位數(shù)的數(shù):");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;d=c*100+b*10+a;printf("%d",d);}買(mǎi)雞:....#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;}printf("%d
6、%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){....z==(100-5*x-3*y)*3
7、&&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計(jì)算x=20+3(x-1):#includevoidmain(){intage(intx)inti,j;scanf(“%d”,&i);j=age(i);printf(“age=%d”,j);}intage(intx){intz