c编程100例c语言c编程实例(编辑修改稿)内容摘要:
fact(j) int j。 { int sum。 if(j==0) 13 sum=1。 else sum=j*fact(j1)。 return sum。 } ============================================================== 【程序 27】 题目:利用递归函数调用方式,将所输入的 5 个字符,以相反顺序打印出来。 : : include main() { int i=5。 void palin(int n)。 printf(\40:)。 palin(i)。 printf(\n)。 } void palin(n) int n。 { char next。 if(n=1) { next=getchar()。 printf(\n\0:)。 putchar(next)。 } else { next=getchar()。 palin(n1)。 putchar(next)。 } } ============================================================== 【程序 28】 题目:有 5 个人坐在一起,问第五个人多少岁。 他说比第 4个人大 2岁。 问第 4个人岁数,他说比第 3 个人大 2 岁。 问第三个人,又说比第 2 人大两岁。 问第 2个人,说比第一个人大两岁。 最后问第一个人,他说是 10 岁。 请问第五个人多大。 :利用递归的方法,递归分为回推和递推两个阶段。 要想知道第五个人岁数,需知道第四人的岁数,依次类推,推到第一人( 10 岁),再往回推。 : age(n) int n。 14 { int c。 if(n==1) c=10。 else c=age(n1)+2。 return(c)。 } main() { printf(%d,age(5))。 } ============================================================== 【程序 29】 题目:给一个不多于 5 位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。 1. 程序分析:学会分解出每一位数,如下解释: : main( ) { long a,b,c,d,e,x。 scanf(%ld,amp。 x)。 a=x/10000。 /*分解出万位 */ b=x%10000/1000。 /*分解出千位 */ c=x%1000/100。 /*分解出百位 */ d=x%100/10。 /*分解出十位 */ e=x%10。 /*分解出个位 */ if (a!=0) printf(there are 5, %ld %ld %ld %ld %ld\n,e,d,c,b,a)。 else if (b!=0) printf(there are 4, %ld %ld %ld %ld\n,e,d,c,b)。 else if (c!=0) printf( there are 3,%ld %ld %ld\n,e,d,c)。 else if (d!=0) printf(there are 2, %ld %ld\n,e,d)。 else if (e!=0) printf( there are 1,%ld\n,e)。 } ============================================================== 【程序 30】 题目:一个 5 位数,判断它是不是回文数。 即 12321 是回文数,个位与万位相同,十位与千位相同。 : 同 29 例 : main( ) { long ge,shi,qian,wan,x。 scanf(%ld,amp。 x)。 wan=x/10000。 qian=x%10000/1000。 shi=x%100/10。 ge=x%10。 if (ge==wanamp。 amp。 shi==qian)/*个位等于万位并且十位等于千位 */ printf(this number is a huiwen\n)。 else printf(this number is not a huiwen\n)。 15 } 【程序 31】 题目:请输入星期几的第一个字母来判断一下是星期几,如果第一个字母一样,则继续 判断第二个字母。 :用情况语句比较好,如果第一个字母一样,则判断用情况语句或 if 语句判断第二个字母。 : include void main() { char letter。 printf(please input the first letter of someday\n)。 while ((letter=getch())!=39。 Y39。 )/*当所按字母为 Y 时才结束 */ { switch (letter) {case 39。 S39。 :printf(please input second letter\n)。 if((letter=getch())==39。 a39。 ) printf(saturday\n)。 else if ((letter=getch())==39。 u39。 ) printf(sunday\n)。 else printf(data error\n)。 break。 case 39。 F39。 :printf(friday\n)。 break。 case 39。 M39。 :printf(monday\n)。 break。 case 39。 T39。 :printf(please input second letter\n)。 if((letter=getch())==39。 u39。 ) printf(tuesday\n)。 else if ((letter=getch())==39。 h39。 ) printf(thursday\n)。 else printf(data error\n)。 break。 case 39。 W39。 :printf(wednesday\n)。 break。 default: printf(data error\n)。 } } } ============================================================== 【程序 32】 题目: Press any key to change color, do you want to try it. Please hurry up! : : include void main(void) { int color。 for (color = 0。 color 8。 color++) { textbackground(color)。 /*设置文本的背景颜色 */ 16 cprintf(This is color %d\r\n, color)。 cprintf(Press any key to continue\r\n)。 getch()。 /*输入字符看不见 */ } } ============================================================== 【程序 33】 题目:学习 gotoxy()与 clrscr()函数 : : include void main(void) { clrscr()。 /*清屏函数 */ textbackground(2)。 gotoxy(1, 5)。 /*定位函数 */ cprintf(Output at row 5 column 1\n)。 textbackground(3)。 gotoxy(20, 10)。 cprintf(Output at row 10 column 20\n)。 } ============================================================== 【程序 34】 题目:练习函数调用 1. 程序分析: : include void hello_world(void) { printf(Hello, world!\n)。 } void three_hellos(void) { int counter。 for (counter = 1。 counter = 3。 counter++) hello_world()。 /*调用此函数 */ } void main(void) { three_hellos()。 /*调用此函数 */ } ============================================================== 【程序 35】 题目:文本颜色设置 : : 17 include void main(void) { int color。 for (color = 1。 color 16。 color++) { textcolor(color)。 /*设置文本颜色 */ cprintf(This is color %d\r\n, color)。 } textcolor(128 + 15)。 cprintf(This is blinking\r\n)。 } ============================================================== 【程序 36】 题目:求 100 之内的素数 : : include include define N 101 main() { int i,j,line,a[N]。 for(i=2。 iN。 i++) a[i]=i。 for(i=2。 isqrt(N)。 i++) for(j=i+1。 jN。 j++) { if(a[i]!=0amp。 amp。 a[j]!=0) if(a[j]%a[i]==0) a[j]=0。 } printf(\n)。 for(i=2,line=0。 iN。 i++) { if(a[i]!=0) {printf(%5d,a[i])。 line++。 } if(line==10) {printf(\n)。 line=0。 } } } ============================================================== 【程序 37】 题目:对 10 个数进行排序 :可以利用选择法,即从后 9 个比较过程中,选择一个最小的与第一个元素交换,下次类推,即用第二个元素与后 8 个 进行比较,并进行交换。 18 : define N 10 main() {int i,j,min,tem,a[N]。 /*input data*/ printf(please input ten num:\n)。 for(i=0。 iN。 i++) { printf(a[%d]=,i)。 scanf(%d,amp。 a[i])。 } printf(\n)。 for(i=0。 iN。 i++) printf(%5d,a[i])。 printf(\n)。 /*sort ten num*/ for(i=0。 iN1。 i++) {min=i。 for(j=i+1。 jN。 j++) if(a[min]a[j]) min=j。 tem=a[i]。 a[i]=a[min]。 a[min]=tem。 } /*output data*/ printf(After sorted \n)。 for(i=0。 iN。 i++) printf(%5d,a[i])。 } ============================================================== 【程序 38】 题目:求一个 3*3 矩阵对角线元素之和 :利用双重 for 循环控制输入二维数组,再将 a[i][i]累加后输出。 : main() { float a[3][3],sum=0。 int i,j。 printf(please input rectangle element:\n)。 for(i=0。 i3。 i++) for(j=0。 j3。 j++) scanf(%f,amp。 a[i][j])。 for(i=0。 i3。 i++) sum=sum+a[i][i]。 printf(duijiaoxian he is %,sum)。 } ============================================================。c编程100例c语言c编程实例(编辑修改稿)
相关推荐
} 输入一个字符串,按相反次序输出其中的所有字符。 include void main() { char str[80],*p=str。 gets(p)。 while(*p!=39。 39。 ) p++。 for(p。 p=str。 p) putchar(*p)。 putchar(39。 39。 )。 } 输入一个一维数组,输出其中的最大值、最小值和平均值。 include void
辑、编译、连接和运行一个 C 程序,即运行一个 C 程序的全过程。 3 通过运行简单的 C程序,初步了解 C程序的基本结构及特性。 二 实验内容和步骤 1 从开 机开始进行操作,熟悉一些常用的 DOS 命令,包括如何建立子目录,文件拷贝,删除文件等。 2 建立自己的子目录,以备存放文件。 3 进入 Turbo C集成环境,熟悉 Turbo C主菜单下各选择项的功能及功能键的使用。 4 输入一简单
an=%d”,n,y/n)。 } ───────────────── 11. 打印如下方阵 1 0 0 0 0 0 1 3 1 0 0 0 1 4 3 3 1 0 1 4 4 3 3 3 1 4 4 4 3 3 1 2 1 4 4 3 1 2 2 2 1 4 1 2 2 2 2 2 1 main( ) { int a[7][7],i,j。 for(i=0。 i7。 i++) for(j=0。
课文的内容和表达有自己的心得,能提出自己的看法和疑问,并 能运用合作的方式,共同探讨疑难问题。 6.在阅读中了解叙述、描写、说明、议论、抒情等表达方式。 7.能够区分写实作品和虚构作品,了解诗歌、散文、小说、戏剧等文学样式。 8.欣赏文学作品,能有自己的情感体验,初步领悟作品的内涵,从中获得对自然、社会、人生的有益启示。 对作品的思想感情倾向,能联系文化背景作出自己的评价
.............................................. 117 ③、污水管道施工工艺框图 .............................................................. 118 ④、燃气管道工程施工工艺框图 .....................................................
反对是好的象征,这表示他在聆听你的说话,实际上,他们是在询问更多的资料。 有时会碰到一些迟疑不决的顾客,对你来说是富有挑战性的,作为一名专业营业员,你的责任是带出顾客的不满。 要更有效地解决顾客的不满。 (一)顾客反对、犹豫购物的原因 16 营业员表现未达专业水平 当营业员表现不热情、或过份热情或对商品提供的资料不足,售货不顺利时表现拙劣会令顾客失去信心或反感。 未清楚真正需要