1、例子:#include main ()tips(); /*caller*/printf(“n Success is about banging on after others have let go”);tips() /*caller*/printf (“n When you reach the end of the rope tie a knot 上述程序的输出结果如下:When you reach the end of the ropt tie a knot printf(“nEnter any number”);scanf(“%d”,fact=rec(a);printf(“Factori
2、al value is%d”,fact);rec(x);int x;int f;if(x=1)return(1);elsef=x*rec(x-1);return(f);其显示的结果为: Factorial value is 2.比较两个数较大的那个:#include main()int a,b,max;scanf (“%d%d”,if (ab)max=a;else max=b;printf (“%d”,max);输出 a+b 的值:#include void main()int a,b,x;scanf (“%d%d”,x=a+b;printf (“%d”,x);输出 a,b 中最大的一位数:#
3、include int max(int x,int y)int z;if (xy) z=x;else z=y;return(z);void main()int a,b,c;scanf (“%d%d”,c=max(a,b);printf (“%dn”,c);输出 Hello:#include int main()printf (“Hello!”);return 0;求 1100 的和:#include int main()int s,n;s=0,n=1;A: s=s+n;n=n+1;if (nvoid main()int x,y,a,b,c;printf (“请输入一个三位数的数:“);scan
4、f(“%d“,a=x/100;b=x%100/10;c=x%10;y=c*100+b*10+a;printf (“n%d“,y);#include void main()int x,a,b,c,d;printf (“请输入一个三位数的数:“);scanf(“%d“,a=x/100;b=x%100/10;c=x%10;d=c*100+b*10+a;printf (“n%dn“,d);买鸡:#include void main()int x,y,z;if(x=0while (xvoid main()int x=0,y=0,z=0;while (xvoid main()int age(int x)i
5、nt i,j;scanf(“%d”,j=age(i);printf(“age=%dn”,j);int age(int x)int z;if(x=1) z=20;else z=age(x-1)+3;return(z);编写程序求圆柱体的表面积和体积:#include #define PI 3.14 /*定义 PI为符号常量,值为 3.14*/void main()float r,h,s,v;printf(“请输入半径 r和高 h的值:n”);scanf(“%f%f”, /*输入半径 r和高 h*/s=2*PI*r*h; /*计算圆柱体表面积*/v=PI*r*r*h; /*计算圆柱体体积*/pri
6、ntf(“s=%f,v=%fn”,s,v);自增,自减运算符的使用:#include void main()int i=5,j=5;int x,y;x=i+;y=+j;printf(“%dt%dn”,-x+,-(+y);printf(“%dt%dt%dt%dn”,i,j,x,y);自增、自减运算符的基本运算:#include void main()int k=4;int x,y,z;x=18-k+;printf(“x=%d”,x);printf(“k=%dn”,k);y=+k+6;printf(“y=%d”,y);printf(“k=%dn”,k);z=+k+k+;printf(“z=%dn”
7、,z);结果:x=14,k=5;y=12,k=6;z=14.输出单个字符:#include void main()char a,b;a=o;b=k;putchar(a);putchar(b);putchar(n);输入字符举例:#include void main()char c;c=getchar(); /*从键盘读入一个字符*/putchar(c); /*显示输入的字符*/猜数游戏:#include #include #include int main()int x,i=0,guess;srand(time(NULL);x=rand()%100+1;printf(“请你猜数:“);dosc
8、anf(“%d“,if(xguess)printf(“你猜小了!n“);elseprintf(“你赢了!n“);break;i+;if (i=10)printf(“随机数是:%dn“,x);printf(“你已经猜 错了 10 次,我赢了,哈哈!n“);break;printf(“请你再猜:“); while(1);#include void main()int a=2,*p=Printf(“%d,%dn“,*p+,*(q+);P=q=&;Printf (“%d%dn“,*p,(*q)+);Printf(“%d%dn“,*p,+(*q);结果为:2,22,24,4(从又向左算)#include Void main()Int a,b,c;Int *pa,*pb,*pc;Pa=pb=pc=Scanf (“%d%d“,pa,pb);Printf (“a=%d,b=%dn“,*pa,*pb);C=a+b;Printf (“c=%dn“,*pc);*pc=a+*pb;Printf (“c=%d从 100 到 200 之间有哪些数除 4 多 2,除 7 多 3,除 9 多 5?#includeint main()for(int i = 100; i Void main()Int *p,i,a10;P=a;For (i=0;i10;i+)Scanf (