【编程要求】
1.编写函数int findword(char *s,char *t,char ch[][20])。函数功能:在由若干句子组成的字符串s中搜索包含字符串t的所有单词,将这些单词存放在数组ch中,函数返回找到的单词格式。称字符串s为“被搜索字符串”,字符串t为“搜索字符串”。
2.编写main函数。函数功能:声明数组s和t,用被搜索字符串和搜索字符串初始化这两个数组。调用函数findword对给定的测试数据进行检索,并将检索到的包含字符串t的所有单词及单词的个数保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【测试数据及运行结果】
被搜索字符串:No living man all things can. Graspall,loseall.
搜索字符串:all
检索结果:all,Graspall,loseall. 3
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
2、编程题
【编程要求】
1.编写函数void josephu(int a[],int b[],int n,int m)实现如下模拟处理功能:a指向的数组中存储了n个人的编号(从1开始按序编号到n)。n个人围坐成一圈,从编号为1 的人开始报数(从1到m报数),凡报到m的人出列。将每次出列的人的编号依次保存在b指向的数组中,直到最后一个人出列为止。
2.编写main函数。用给定的测试数据调用josephu函数,将经函数处理后得到的n个依次出列的人的编号保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【测试数据及运行结果】
测试数据: n=10,m=3
运行结果: 3, 6, 9, 2, 7, 1, 8, 5, 10, 4
My exam number is :0112400123(考生本人准考证号)
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
3、编程题
【编程要求】
1.编写函数void squeeze(char *s1,char *s2,char *s3),其功能是:从s1指向的字符串中删去所有在s2指向的字符串中已出现的字符,将从s1中删除的字符保存到s3指向的数组中。
2.编写main函数。用给定的测试字符串s1和s2调用squeeze函数,将处理后的s1字符串和s3字符串保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【测试数据及运行结果】
测试数据:
s1:“abbcdefgghiijkl”,s2:“bdglkw”
运行结果:
s1: acefhiij, s3:bbdggkl
my exam number is :0112400123(本人准考证号)
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
4、编程题
【编程要求】
1.编写函数char *insert(char *p),其功能是:在p指向的字符串中所有数字字符子串前插入一个符号’-’。函数返回p字符串的首地址。
2.编写main函数。用给定的测试字符串初始化数组,调用insert函数对字符串做处理,将结果字符串保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【测试数据及运行结果】
测试数据:
AB1CD12EF123GH
运行结果:
AB-1CD-12EF-123GH
my exam number is :0112400123(本人准考证号)
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
5、编程题
【编程要求】
1.编写函数void fun(int array[],int n),将array数组中的前n个整数按从大到小的顺序排序。
2.编写main函数。从键盘上输入一个正整数,求出该位是几位数,按从左到右的顺序显示各位数字,用这些数字组成一个最小正整数(调用fun函数),将以上三项结果保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
6、编程题
【编程要求】
1.编写函数fun,它的功能是:求出这N个学生的平均分,由函数值返回。例如,若学生的成绩是:85,76,69,85,91,72,,87,则平均分应当是:78.625
2.编写main函数。将N名学生的成绩在主函数中放入一个带头节点的链表结构中,h指向链表的头节点。并调用函数fun,将结果及函数返回值写入到文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
7、编程题
【编程要求】
1.编写函数fun,它的功能是:移动字符串中的内容,移动的规则如下:把第1到第m个字符平移到字符串的最后,把第m+1到最后的字符串移动字符串的前部。例如:字符串中原有的内容为:ABCDEFGHIJK,m的值为3,则移动后,字符串中的内容应该是:DEFGHIJKABC.
2.编写main函数。在main函数中初始化一个字符串,调用函数fun,将结果字符串及函数返回值写入到文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
8、编程题
【程序功能】
以矩阵的行作为排序的交换单位,使得排序后的矩阵按指定列的元素值递减有序。
【编程要求】
1.编写函数void sort(int x[][4],int n,int col)。它的功能是:对x指向的二维数组(该数组中保存了一个n*4矩阵)以行作为交换单位,按照下标为col的列元素值做递减排序。
2.编写main函数。函数功能:声明一个3行4列二维数组并用测试数据初始化该数组,调用sort函数对该数组中保存的矩阵按第3列(列下标为2)排序,将排序后二维数组中的矩阵输出到屏幕并用写文件函数保存到结果文件myf2.out中。最后将考生本人的准考证号字符串也保存到结果文件myf2.out中。
【测试数据与运行结果】
测试数据(排序前):
101 80 60 90
102 70 90 50
103 60 70 80
运行结果(按第3列排序后):
102 70 90 50
103 60 70 80
101 80 60 90
my exam number is :考生本人准考证号字符串
【要求】
源程序文件名必须取为myf2.c,输出结果文件名必须取为myf2.out
数据文件的打开、使用和关闭均用C语言标准库中缓冲文件系统的文件操作函数实现。
源程序文件和运行结果文件必须保存在考试盘的根目录下,供阅卷用。
不要复制扩展名为OBJ和EXE的文件到考试盘上。
1.编程:
#include #include #include #include int findword(char *s,char *t,char ch[][20]) { char tmp[10][20]; int cn=0,i,count=0,j,m,n,len,lena; while(*s) { while(!isalpha(*s)&&*s) s++; if(isalpha(*s)&&*s) { i=0; while(isalpha(*s)&&*s) { tmp[cn][i++]=*s; s++; } tmp[cn][i]=0; cn++; } } for(i=0;i len=strlen(t); for(i=0;i lena=strlen(tmp[i]); for(j=0;j for(m=j,n=0;n if(n>=len) { strcpy(ch[count++],tmp[i]); break; } } } return count; } void main() { char *s=\"No living man all things can. Graspall, loseall.\ int n,i; FILE *fp; fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open this file.\");exit(-1);} n=findword(s,t,ch); for(i=0;i printf(\"%s \ fprintf(fp,\"%s \ } printf(\"\\nwords NO: %d\ fprintf(fp,\"\\nwords NO: %d\ fprintf(fp,\"\\nmy no is 0002499999.\"); fclose(fp); } 2.编程: #include #include void josephu(int a[],int b[],int n,int m) { int i=0,flag=1,cn=0; while(cn if(a[i]==0) i=(i+1)%10; else if(flag<3) { i=(i+1)%10; flag++; } else if(flag==3) { b[cn++]=a[i]; a[i]=0; flag=1; i=(i+1)%10; } } } void main() { int n,m,i,a[100],b[100]; FILE *fp; fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open this file.\");exit(-1);} printf(\"enter n,m:\");scanf(\"%d,%d\ for(i=0;i josephu(a,b,n,m); for(i=0;i printf(\"%4d\ fprintf(fp,\"4d\ } fprintf(fp,\"\\nmy no is 0002499999.\"); fclose(fp); } 3.编程: #include #include void squeeze(char *s1,char *s2,char *s3) { char *p,*q; int i=0; while(*s1) { p=s2; while(*p&&*p!=*s1) p++; if(*p) { s3[i++]=*s1; q=s1; while(*q) { *q=*(q+1); q++; } s1--; } s1++; } s3[i]=0; } void main() { FILE *fp; char *s1=\"abbcdefgghiijkl\ fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open this file.\");exit(-1);} squeeze(s1,s2,s3); printf(\"s1:%s\\n\ fprintf(fp,\"s1:%s\\n\ printf(\"s3:%s\\n\ fprintf(fp,\"s3:%s\\n\ fprintf(fp,\"my exame number is 0002499999.\"); fclose(fp); } 4.编程: #include #include #include #include char *insert(char *p) { char *q=p,temp[20]; while(*p) { while(*p&&isalpha(*p)) p++; if(*p) { strcpy(temp,p); *p++='-'; strcpy(p,temp); } while(*p&&isdigit(*p)) p++; } return q; } void main() { FILE *fp; char *p=\"AB1CD12EF123GH\ fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open this file.\");exit(-1);} q=insert(p); printf(\"%s\ fprintf(fp,\"%s\ fprintf(fp,\"\\nmy no is 0002499999.\"); fclose(fp); } 5.编程: #include void fun(int array[],int n) { int i,j,t; for(i=0;i for(j=i+1;j } } void main() { int a[5]={0},m,n=0,i=0,min=0; FILE *fp; fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't\");exit(-1);} clrscr(); scanf(\"%d\ if(m/10000!=0) n=5; else if(m/1000!=0) n=4; else if(m/100!=0) n=3; else if(m/10!=0) n=2; else n=1; fprintf(fp,\"%d has %d bits:\ printf(\"%d has %d bits.\ i=n-1; while(m!=0) { a[i--]=m%10; m/=10; } for(i=0;i printf(\"\\n\"); fprintf(fp,\"\\n\"); fun(a,n); i=n-1; while(i>=0) { min=min*10+a[i]; i--; } printf(\"min is %d\ fprintf(fp,\"min is %d\ fclose(fp); } 6.编程: #include #include #define N 8 typedef struct slist { double score; struct slist *next; }STREC; STREC *creatlist(double s[]) { STREC *head,*p,*q; int i=0; head=p=(STREC *)malloc(sizeof(STREC)); p->next=0; while(i q=(STREC *)malloc(sizeof(STREC)); q->score=s[i];p->next=q;p=q;i++; } p->next=0; return head; } double fun(STREC *h) { STREC *p; double aver=0.0; p=h->next; while(p) { aver+=p->score/N; p=p->next; } return aver; } void main() { double s[N]={85,76,69,85,91,72,,87},aver; STREC *head; int i=0; FILE *fp; head=creatlist(s); aver=fun(head); fp=fopen(\"myf2.out\ if(fp==0) { printf(\"cann't open this file\"); exit(-1); } while(i printf(\"s[%d]:%f\\n\ fprintf(fp,\"%f\ } printf(\"aver=%f\ fprintf(fp,\"\\naver=%f\ fclose(fp); } 7.编程: #include #include void fun(char *s,int m) { int i=0,n=strlen(s); char t[100]=\"\"; while(i t[i]=*(s+i);i++; } for(i=m;i s[i-m]=s[i]; } for(i=n-m;i s[i]=t[i-n+m]; } } void main() { char *s=\"\"; int m; FILE *fp; fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open the file\");exit(-1);} printf(\"enter s:\"); gets(s);/*puts(s); */ printf(\"enter m:\"); scanf(\"%d\ fun(s,m); puts(s); fprintf(fp,\"%s\ fclose(fp); } 8.编程: #include #include void sort(int x[][4],int n,int col) { int p,q,j,t,max,indx; for(p=0;p indx=p;max=x[p][col]; for(q=p+1;q { max=x[q][col]; indx=q; } for(j=0;j<4;j++) { t=x[p][j];x[p][j]=x[indx][j];x[indx][j]=t; } } } void main() { int x[3][4]={{101,80,60,90},{102,70,90,50},{103,60,70,80}},i,j; FILE *fp; fp=fopen(\"myf2.out\ if(fp==0) {printf(\"can't open this file.\");exit(-1);} sort(x,3,2); for(i=0;i<3;i++) { for(j=0;j<4;j++) { printf(\"%4d\j]); fprintf(fp,\"%4d\j]); } printf(\"\\n\"); fprintf(fp,\"\\n\"); } fprintf(fp,\"my no is 0002499999.\"); fclose(fp); }
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- gamedaodao.com 版权所有 湘ICP备2022005869号-6
违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务