




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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()1 / 9int 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;re
4、turn(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
5、)#include <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
6、=x%100/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
8、*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):#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
9、 z;if(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 自增,自减运算符的使用:#i
10、nclude <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);
11、结果:x=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
12、main()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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 房屋改造装饰工程精细化施工组织设计及实施方案研究
- 马铃薯汁对葡萄砧木生长与繁殖的影响研究
- 全球及中国开颅器行业市场发展分析及前景趋势与投资发展研究报告2025-2028版
- 全球及中国巡逻船行业市场发展分析及前景趋势与投资发展研究报告2025-2028版
- 全球及中国婴儿身高杆行业市场发展分析及前景趋势与投资发展研究报告2025-2028版
- 全球及中国增强购物系统行业市场发展现状及发展前景研究报告2025-2028版
- 全球及中国医疗保险交易所行业市场发展分析及前景趋势与投资发展研究报告2025-2028版
- 2025年泌尿系统感染用药项目合作计划书
- 智能恒温恒湿机行业跨境出海战略研究报告
- 智能可穿戴相机行业跨境出海战略研究报告
- 经导管主动脉瓣置换术(TAVR)患者的麻醉管理
- 2024-2030年中国预付卡和礼品卡行业市场发展趋势与前景展望战略分析报告
- 国能辽宁北票 200MW 风力发电项目地质灾害危险性评估报告
- 《中电联团体标准-220kV变电站并联直流电源系统技术规范》
- 桥梁博士毕业设计电子版
- MOOC 犯罪心理学-西南政法大学 中国大学慕课答案
- 家族信托与家族财富传承
- 杭港地铁施工培训课件
- 电能质量技术监督培训课件
- 丰富多彩的课间活动课件
- 蓝色卡通风太阳系八大行星知识天文知识科普宣传
评论
0/150
提交评论