版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、例子:l #include <stdio.h>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 & hang on”,)0;上述程序的输出结果如下:When you reach the end of the ropt tie a knot & hang on.Success is about
2、hanging on after others have let go.l #include <stdio.h>main()int a,fact;printf(“nEnter any number”);scanf(“%d”,&a);fact=rec(a);printf(“Factorial 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.l 比较两个数较大的那个:#include <stdio.h
3、>main()int a,b,max;scanf (“%d%d”,&a,&b);if (a>b)max=a;else max=b;printf (“%d”,max);l 输出a+b的值:#include <stdio.h>void main()int a,b,x;scanf (“%d%d”,&a,&b);x=a+b;printf (“%d”,x);l 输出a,b中最大的一位数:#include <stdio.h>int max(int x,int y)int z;if (x>y) z=x;else z=y;return(
4、z);void main()int a,b,c;scanf (“%d%d”,&a,&b);c=max(a,b);printf (“%dn”,c);l 输出Hello:#include <stdio.h>int main()printf (“Hello!”);return 0;l 求1100的和:#include <stdio.h>int main()int s,n;s=0,n=1;A: s=s+n;n=n+1;if (n<=100)goto A;printf (“%d”,s);l 请输入一个三位数,将其各位逆序输出:(如153,输出351)#inc
5、lude <stdio.h>void main()int x,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 ("n%d",y);#include <stdio.h>void main()int x,a,b,c,d;printf ("请输入一个三位数的数:");scanf("%d",&x);a=x/100;b=x%10
6、0/10;c=x%10;d=c*100+b*10+a;printf ("n%dn",d);买鸡:#include <stdio.h>void main()int x,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&&a
7、mp;y=100-x-z;z=(100-5*x-3*y)*3&&z=100-x-y;#include <stdio.h>void main()int x=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);#include <stdio.h>void main()int x=0,y=0,z=0;while (x<=19)while (y<=33)while (z<=100)z=(100-5*x-3*
8、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):#include <stdio.h>void main()int age(int x)int i,j;scanf(“%d”,&i);j=age(i);printf(“age=%dn”,j);int age(int x)int z;if
9、(x=1) z=20;else z=age(x-1)+3;return(z);l 编写程序求圆柱体的表面积和体积:#include <stdio.h>#define PI 3.14 /*定义PI为符号常量,值为3.14*/void main()float r,h,s,v;printf(“请输入半径r和高h的值:n”);scanf(“%f%f”,&r,&h); /*输入半径r和高h*/s=2*PI*r*h; /*计算圆柱体表面积*/v=PI*r*r*h; /*计算圆柱体体积*/printf(“s=%f,v=%fn”,s,v);l 自增,自减运算符的使用:#includ
10、e <stdio.h>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);l 自增、自减运算符的基本运算:#include <stdio.h>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”,z);结果:x=
11、14,k=5;y=12,k=6;z=14.l 输出单个字符:#include <stdio.h>void main()char a,b;a=o;b=k;putchar(a);putchar(b);putchar(n);l 输入字符举例:#include <stdio.h>void main()char c;c=getchar(); /*从键盘读入一个字符*/putchar(c);/*显示输入的字符*/猜数游戏:#include <stdio.h>#include <stdlib.h>#include <time.h>int main(
12、)int x,i=0,guess;srand(time(NULL);x=rand()%100+1;printf("请你猜数:");doscanf("%d",&guess);if(x<guess)printf ("你猜大了!n");else if(x>guess)printf("你猜小了!n");elseprintf("你赢了!n");break;i+;if (i>=10)printf("随机数是:%dn",x);printf("你已经猜 错
13、了10次,我赢了,哈哈!n");break;printf("请你再猜:"); while(1);#include <stdio.h>void main()int a=2,*p=&a,*q=&a;Printf("%d,%dn",*p+,*(q+);P=&a;q=&Printf ("%d%dn",*p,(*q)+);Printf("%d%dn",*p,+(*q);结果为:2,2 2,2 4,4(从又向左算)#include <stdio,h>Void main()Int a,b,c;Int *pa,*pb,*pc;Pa=&a;pb=&b;pc=&c;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?#include<stdio.h&
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 空气动力学方程:RANS方程:RANS方程的高级应用与研究进展
- 中职教育三年级上学期装备制造大类《简易六面体的逆向建模》课件
- 小学五年级上学期英语《Unit 5 Part B Let's learn》教学课件
- 电力有限公司科技项目可行性方案研究报告
- 云南省第二十一届职工职业技能大赛叉车司机竞赛考试题库(含答案)
- 三级人工智能训练师(高级)职业技能等级认定考试题库-上(单选题部分)
- 内燃机车司机(学标考标)必知必会考试题库(含答案)
- 第十八届“振兴杯”全国青年职业技能大赛(职工组)钳工决赛试题库-下(判断题)
- 2024年全国职业院校技能大赛中职组(装配式建筑构件安装赛项)考试题库(含答案)
- 2024年全国职业院校技能大赛高职组(建筑装饰数字化施工赛项)备赛试题库含答
- 污水系统运维方案
- 李天元旅游学概论第7版课后习题答案
- 人防地下室墙体后开洞整改施工方案(防办)
- (精选word)洪恩识字-生字卡片1-200
- 西式面点制作教案
- 煤矿《机电管理体系文件》
- 《寄小读者》整本书阅读计划及教学设计
- (中职)Office办公软件应用案例教程-word第3课 一封家书我来写ppt教学课课件
- 中职英语基础模块2教案
- 汽车机械制图
- 中职网络综合布线整套课件完整版ppt教学教程最全电子讲义教案(最新)
评论
0/150
提交评论