![[理学]标准C语言程序设计及应用周纯杰每章课后编程题.doc_第1页](http://file.renrendoc.com/FileRoot1/2019-1/12/e491c7f4-c838-45e4-bab3-a276b69dfbc8/e491c7f4-c838-45e4-bab3-a276b69dfbc81.gif)
![[理学]标准C语言程序设计及应用周纯杰每章课后编程题.doc_第2页](http://file.renrendoc.com/FileRoot1/2019-1/12/e491c7f4-c838-45e4-bab3-a276b69dfbc8/e491c7f4-c838-45e4-bab3-a276b69dfbc82.gif)
![[理学]标准C语言程序设计及应用周纯杰每章课后编程题.doc_第3页](http://file.renrendoc.com/FileRoot1/2019-1/12/e491c7f4-c838-45e4-bab3-a276b69dfbc8/e491c7f4-c838-45e4-bab3-a276b69dfbc83.gif)
![[理学]标准C语言程序设计及应用周纯杰每章课后编程题.doc_第4页](http://file.renrendoc.com/FileRoot1/2019-1/12/e491c7f4-c838-45e4-bab3-a276b69dfbc8/e491c7f4-c838-45e4-bab3-a276b69dfbc84.gif)
![[理学]标准C语言程序设计及应用周纯杰每章课后编程题.doc_第5页](http://file.renrendoc.com/FileRoot1/2019-1/12/e491c7f4-c838-45e4-bab3-a276b69dfbc8/e491c7f4-c838-45e4-bab3-a276b69dfbc85.gif)
已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
P71#include #include void main() clrscr(); int i; int sum; sum=0; printf(Enter i:); scanf(%d,&i); while (i=100) sum=sum+i; i+; printf(sum=%dn,sum); getch();P96(6)#include #include void main() int a, b, sum, i; a=8; b=1; sum=8; for(i=1; i=9;i+); b=b+3; a=a+b; sum+=a; printf(sum=%dn,sum); getch();P97(18)#include #include void main() float x, a, b, expx; while(1) char i; a=1; expx=1; b=1; printf(please input x:); scanf(%f,&x); if(x1e-6) break; for(i=1;i+) a*=x; b*=i; expx+=a/b; if(a/b1e-6) break; else continue; printf(expx=%fn,expx); getch(); clrscr(); P90#include #include void main() unsigned long int a, i; for(a=10;a=100;a+) for(i=2;i=a) printf(%dt,a); getch();P97(9)#include #include #include void main() unsigned int a, b, i; randomize(); a=random(65535); for(i=1;i1) printf(Right! You have guessed %d times.n,i); printf(Enter any singel number to break.n); scanf(%d,&b); if(1) break; else if(ab) printf(Wrong! Your number is small.n); continue; else printf(Wrong! Your number is large.n); continue; P97(19)#include #include #include void main() float x, a; char i; x=1.0; printf(Please input a(ji suan a de ping fang gen):); scanf(%f,&a); for(i=1;i+) if(fabs(x-(x+a/x)/2)1e-5) x=(x+a/x)/2; break; else x=(x+a/x)/2; printf(x=%fn,x); getch(); clrscr();P97(16)#include #include void main() long int x, S; int a, n, i; printf(Please input a, n:); scanf(%d,%d,&a,&n); S=0; x=0; for(i=1;i=n;i+) x=x*10+a; S=S+x; printf(S=%ldn,S); getch();P97(11)#include #include void main() int i; int a, b; printf(Please input a, b:); scanf(%d,%d,&a,&b); for(i=a0;i-) if(a%i=0&b%i=0) printf(The max is %d.n,i); break; for(i=ab?a:b;i+) if(i%a=0&i%b=0) printf(The min is %d.n,i); break; getch();P139(2)#include#includevoid main() int n, x; int i, j; int a100; printf(nInput the number of the group:n); scanf(%d,&n); printf(Input the group of numbers:n); for(i=0;i=an-1) an=x; printf(Now the group is:n); for(i=0;in+1;i+) printf(%d ,ai); else for(i=0;in;i+) if(xi;j-) aj=aj-1; ai=x; break; printf(Now the group is:n); for(i=0;in+1;i+) printf(%d ,ai); getch(); P139(6)#include#include#includevoid main() int grade100, tg; char name10010, tn100; int n; int i, j; printf(Input the number:n); scanf(%d,&n); printf(Input the grade and name:); for(i=0;in;i+) printf(n); scanf(%d,&gradei); scanf(%s,&namei); for(i=0;in-1;i+) for(j=0;jn-1-i;j+) if(gradejgradej+1) tg=gradej; gradej=gradej+1; gradej+1=tg; strcpy(tn,namej); strcpy(namej,namej+1); strcpy(namej+1,tn); printf(From large to small by grade:); for(i=0;in;i+) printf(n); printf(%d ,gradei); puts(namei); P139(7)#include#include#define SIZE 4void main() int aSIZESIZE; int i, j, t, max, n=0; int row=0, column=0; printf(Input a two-dimensional array:); for(i=0;iSIZE;i+) printf(n); for(j=0;jSIZE;j+) scanf(%d,&aij); for(i=0;iSIZE;i+) max=ai0; for(j=0;jSIZE;j+) if(maxaij) max=aij; row=i; column=j; for(t=0;tSIZE;t+) if(atcolumnmax) break; if(t=SIZE) printf(One saddle point is %d(%d, %d).n,max, row, column); n+; if(i=SIZE&n=0) printf(There is no saddle point.n); P139(5)#include#include#includevoid main() char str1100, str2100; int i, j; printf(nInput string1 and string2:n); gets(str1); gets(str2); for(i=strlen(str1),j=0;jstrlen(str2);i+,j+) str1i=str2j; str1strlen(str1)+strlen(str2)=0; printf(Now the string is:n); puts(str1); getch(); clrscr();P170(4)#include #include #include void main()char str100, *pstr=str;long int a50=0, *pa=a;int time, flag, n, i;clrscr();printf(Please input a string:n);gets(str);for(time=1, flag=0; *pstr!=0; pstr+)if(isdigit(*pstr)flag=1;*pa*=time;*pa+=(*pstr-0);time=10;n=pa-a;elseif(flag=1)pa+;time=1;flag=0;pa=a;printf(nNumber:%dn,n);for(i=0; i=n; i+)printf(a%d=%ldn,i,pai);getch();P170(6)#include #include #include #define N 6void main()char strN20, *pN, *temp;char *pp=p;int i;clrscr();printf(Please %d strings:n,N);for(i=0; iN; i+)gets(stri);pi=stri;for(i=0; iN-1; i+)pp=p;while(*pp-p0)temp=*pp;*pp=*(pp+1);*(pp+1)=temp;printf(nIn order:n);for(i=0; iN; i+)puts(*(p+i);getch();P170(1)#include #include #include void main()char str1100, str2100;char *p1=str1, *p2=str2;int n=0;clrscr();printf(Please input string1 and string2:n);gets(str1);gets(str2);while(*p1!=0&*p2!=0)if(*p1+=*p2+)n+;printf(Number of the same char:%d,n);getch();P170(3)#include #include #include #define N 20void main()char str1N, str2N;char *p1=str1, *p2=str2;int m;clrscr();printf(Please input a string:n);gets(str1);printf(nPlease input m:n);scanf(%d,&m);while(mstrlen(str1)|m1)printf(nError!nPlease input m:);scanf(%d,&m);p1+=m-1;while(*p2+=*p1+)!=0);*p2=0;puts(str2);getch();P170(7)#include #include #include void main()char str100, *p=str, temp;int i, n;clrscr();printf(Please input a string:n);gets(str);n=strlen(str);printf(nThe length of the string is %d.,n);for(i=0; in/2; i+)temp=*(p+i);*(p+i)=*(p+n-i-1);*(p+n-i-1)=temp;printf(nNow the string is:n);puts(str);getch();P170(8)#include #include #include #define N 5void main()char text500, *p;int i;char sN20=from,in,at,an,on;clrscr();printf(Please input the text:n);gets(text);for(i=0; iN; i+)while(1)p=strstr(text,si);if(p!=NULL)strcpy(p,p+strlen(si)+1);elsebreak;printf(nAfter deleting frominatanon,the text is:n);puts(text);getch();P170(8)#include #include #include #define N 500#define IsnotLetter(x) (!(x)=A&(x)=a&(x)=z)/IsnotLetter(x) stands for that x is not a letter.void delete_word(char *pstr, char *pword);int one_word(char *pstr, char *p, int n);/* one_word is used to judge whether the son string p(n is its length) in the string pstr is a single word. */void main()char textN; clrscr();printf(Please input a text:n);gets(text);delete_word(text, from);delete_word(text, in);delete_word(text, at);delete_word(text, an);delete_word(text, on);printf(nAfter deleting frominatanon, the text is:n);puts(text);getch();void delete_word(char *pstr, char *pword)char *p, *pflag=pstr;int word_length;word_length=strlen(pword);while(1)p=strstr(pflag,pword);if(p=pflag)pflag+;if(p!=NULL&one_word(pstr, p, word_length)strcpy(p, p+word_length);if(*p= )strcpy(p, p+1);else if(p=NULL)break; pflag+;int one_word(char *pstr, char *p, int n)if(p=pstr&IsnotLetter(*(p+n)return 1;else if(p!=pstr&IsnotLetter(*(p-1)&IsnotLetter(*(p+n)return 1;else return 0;P230(4)#include #include #include #define N 20void delete_c(char *p, char c);void main()char strN, c;clrscr();printf(Please input a string:n);gets(str);printf(nPlease input the char you want to delete:n);scanf(%c,&c);delete_c(str, c);printf(nNow the string is:n);puts(str);getch();void delete_c(char *p, char c)for( ;*p!=0; p+)if(*p=c)strcpy(p, p+1);p-;P230(1)#include #include long int SquSum(int x, int y);void main()int a, b;long int c;clrscr();printf(Please input a,b:n);scanf(%d,%d,&a,&b);c=SquSum(a, b);printf(na2+b2=%ld,c);getch();long int SquSum(int x,int y)return(x*x+y*y);P230(2)#include #include long int min(int x, int y);int max(int x, int y);void main()int a, b, max1;long int min1;clrscr();printf(Please input a,b:n);scanf(%d,%d,&a,&b);max1=max(a, b);min1=min(a, b);printf(nmax common denominator:%d,max1);printf(nmin common multiple:%ld,min1);getch();int max(int x, int y)int temp;if(xy)temp=x;x=y;y=temp;while(y!=0)temp=x%y;x=y;y=temp;return x;long int min(int x, int y) return (x*y)/max(x, y);P230(5)#include #include int judge_sushu(long int x);void main()long int a;clrscr();printf(Please input a int number:n);scanf(%ld,&a);if(judge_sushu(a)printf(It is a sushu.);elseprintf(It isnt a sushu.);getch();int judge_sushu(long int x)int i;for(i=2; i=x/2; i+)if(x%i=0)return 0; return 1;P231(6)#include #include #define N 20void my_strcat(char *p, char *p1, char *p2);void main()char s1N, s2N, sN*2;clrscr();printf(Please input string1 and string2:n);gets(s1);gets(s2);my_strcat(s, s1, s2);printf(nAdd string2 to the end of string1:n);puts(s);getch();void my_strcat(char *p, char *p1, char *p2)for( ;*p1!=0; p+,p1+)*p=*p1;for( ;*p2!=0; p+,p2+)*p=*p2;*p=0;P231(7)#include #include #define N 50void str_tongji(char *pstr, int *pnum);void main()char strN;int num4=0,0,0,0;clrscr();printf(Please input a string:n);gets(str);str_tongji(str, num);printf(nLetter:%dn,num0);printf(Figure:%dn,num1);printf(Space:%dn,num2);printf(Other:%dn,num3);getch();void str_tongji(char *pstr, int *pnum)for( ;*pstr!=0; pstr+)if(*pstr=A&*pstr=a&*pstr=0&*pstr=9)pnum1+;else if(*pstr= )pnum2+;elsepnum3+;P231(9)#include #include #define N 10void sort(int *pnum, int n, int flag);void main()int numN=0, n, flag, i;clrscr();printf(How many ints will yo input:n);scanf(%d,&n);printf(nNow, input the ints one by one:n);for(i=0; in; i+)scanf(%d,&numi);printf(How to sort them?n);printf(From large to small: input 1.n);printf(from small to large: input any other figure.n);scanf(%d,&flag);sort(num, n, flag);printf(nNow, they are:n);for(i=0; in; i+)printf(%dt,numi);getch();void sort(int *pnum, int n, int flag)int i, j, temp;if(flag=1)for(i=0; in-1; i+)for(j=0; jn-i-1; j+)if(pnumjpnumj+1)temp=pnumj;pnumj=pnumj+1;pnumj+1=temp;elsefor(i=0; in-1; i+)for(j=0; jpnumj+1)temp=pnumj;pnumj=pnumj+1;pnumj+1=temp;P231(10)#include #include #include #define LINE 10#define SIZE 100int input(char (*ptext)SIZE, int n);int find(char (*ptext)SIZE, int n, int flag);void main()char textLINESIZE;int n, line_num, flag;clrscr();printf(Please input a text less than %d lines, end with a space in a single line:n,LINE);n=input(text, LINE);printf(nInput 1 for the max line,others for the min line:);scanf(%d,&flag);line_num=find(text, n, flag);printf(nThe line is:n);puts(textline_num);getch();int input(char (*ptext)SIZE, int n)int i;for(i=0; in; i+)gets(ptexti);if(strcmp(ptexti, )=0)break;return i;int find(char (*ptext)SIZE, int n, int flag)int i, line_num=0;if(flag=1)for(i=1; i0)line_num=i;elsefor(i=1; in; i+)if(strcmp(ptexti, ptextline_num)0)line_num=i;return line_num;P231(14)#include #include #include #define MAX 10#define SIZE 20int input(char (*p)SIZE, int max);void sort(char (*p)SIZE, int n);void output(char (*p)SIZE, int n);void main()char strMAXSIZE;int n;clrscr();printf(Please input less than %d strings, end with string :n,MAX);n=input(str, MAX);sort(str, n);printf(nAfter sorted:n);output(str, n);getch();int input(char (*p)SIZE, int max)int i;for(i=0; imax; i+)gets(pi);if(strcmp(pi, )=0)break;return i;void sort(char (*p)SIZE, int n)int i, j;char tempSIZE;for(i=0; in-1; i+)for(j=0; j0)strcpy(temp, pj);strcpy(pj, pj+1);strcpy(pj+1, temp);void output(char (*p)SIZE, int n)int i;for(i=0; in; i+)puts(pi);P266(4)#include #include #include #include #define MAX 20 /The largest number of studentstypedef structint year;int month;int day;DATE;typedef structchar number20;int stunum;DATE sheet;CLASS;typedef structchar number20;char name20;int grade4;float aver;STUDENT;void input_class(CLASS *p);void input_student(STUDENT *p, int n);void average(STUDENT *p, int n);float remain_2float(float x); /Remain 2 figures after the point.void sort(STUDENT *p, int n);void output(CLASS *pc, STUDENT *ps, int n);void main()CLASS cla;STUDENT stuMAX;clrscr();input_class(&cla);input_student(stu, cla.stunum);average(stu, cla.stunum);sort(stu, cla.stunum);output(&cla, stu, cla.stunum);getch();void input_class(CLASS *p)char s20;printf(Please input the class information:);printf(nClass number:);gets(p-number);printf(Number of students:);gets(s);p-stunum=atoi(s);printf(Date:n);printf(year:);gets(s);p-sheet.year=atoi(s);printf(month:);gets(s);p-sheet.month=atoi(s);printf(day:);gets(s);p-sheet.day=atoi(s);printf(n);void input_student(STUDENT *p, int n)int i, j, s3;printf(Now, please input the students information:n);for(i=0; in; i+)printf(Number:);gets(pi.number);printf(Name:);gets();for(j=0; j4; j+)print
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 卫生管理领域交叉学科题及答案
- 激光在工业中的应用案例试题及答案
- 全面透视光电工程师证书考试难点及试题及答案
- 综合性临床执业医师考试试题及答案
- 竞争激烈的卫生管理证书考试环境试题及答案
- 英语晋级测试题及答案
- 药物经济学在药物开发中的应用试题及答案
- 深入理解育婴师考试中的心理学运用试题及答案
- 激光技术工程师资格考试的机遇与挑战试题及答案
- 疫情防控面试题及答案
- 课程《种子经营管理学》电子课件(全)
- 双减下小学数学低段作业设计与布置课件
- 颜色标准LAB值对照表
- 一年级数学下册课件-1. 补砖问题4-人教版(共10张PPT)
- 螺杆泵工作原理和工况诊断方法
- 医患沟通技巧(PPT)课件
- 真理诞生于一百个问号之后(优秀)(课堂PPT)
- 污水处理厂防汛应急演练方案
- 2020最新八年级下册《道德与法治》知识点总结(最全版)
- 慢性阻塞性肺疾病(COPD)的药物治疗
- 家装施工验收手册(共13页)
评论
0/150
提交评论