商标购买网站,世界互联网峰会视频,微信小程序开发常见问题,应用商店免费下载1.编写一个名为mystrcpy的函数#xff0c;实现将字符串str1的偶数位子的字符的拷贝到另一个字符串str2中。并编写主函数#xff0c;在主函数中从键盘读入一个长度100的字符串str1#xff0c;然后调用函数mystrcpy#xff1b;最后输出str2#xff0c;例如#xff0c;读…1.编写一个名为mystrcpy的函数实现将字符串str1的偶数位子的字符的拷贝到另一个字符串str2中。并编写主函数在主函数中从键盘读入一个长度100的字符串str1然后调用函数mystrcpy最后输出str2例如读入“abcdefgh”,则输出bdfh.
#include stdio.hvoid mystrcpy(char *str1,char *str2){int i0,j0;while(str1[i]!\0){if((i1)%20){str2[j]str1[i];j;}i;}
}int main(){char str1[]abcdefgh;char str2[100];mystrcpy(str1,str2);printf(%s,str2);
}
2.编写一个函数将一维数组转换成一个N阶方阵二维数组矩阵的行数由函数的参数指定。然后再main()中调用该函数并打印输出该仿真的对角线上的值
#include stdio.h
#include stdlib.h
#include math.hvoid changesqure(int *a,int n,int **arr,int size){int i,j0,k0;for(i0;in;i){arr[j][k]a[i];k;if(k!0k%size0){j;k0;}}
}int main(){int a[]{1,2,3,4,5,6,7,8,9};int n sizeof(a)/sizeof(a[0]);int sizesqrt(n);int **arr (int **)malloc(size*sizeof(int *));int i,j;for(i0;isize;i)arr[i](int *)malloc(size*sizeof(int));changesqure(a,n,arr,size);for(i0;isize;i){for(j0;jsize;j)if(ij)printf(%d ,arr[i][j]);printf(\n);}
}
3.编写一个函数求2个数的最小公倍数并输出。要求在主函数中从键盘读入2个正的int型整数求他们的最小公倍数并输出
#include stdio.hint gcd(int x,int y) {if(y0)return x;return 1.0*x*y/gcd(y,x%y);
}4.某班学生信息包括学号字符串长度不超过8位、姓名没有空格的字符串长度不超过20位和两门课程的成绩。请写出学生结构体并编写函数CreatList创建学生链表
#include stdio.h
#include stdlib.htypedef struct student{char num[8];char name[20];int score1;int score2;struct student *next;
}student;struct student *CreatList(int n){struct student *head(struct student*)malloc(sizeof(struct student));head-nextNULL;struct student *prehead;int i;for(i0;in;i){struct student *p(struct student*)malloc(sizeof(struct student));scanf(%s %s %d %d,p-num,p-name,p-score1,p-score2);p-nextpre-next;pre-nextp;}return head-next;
}
5.将上题的学生链表信息读出并写入文件student.txt
#include stdio.h
#include stdlib.htypedef struct student{char num[8];char name[20];int score1;int score2;struct student *next;
}student;void writelist(struct student *head){FILE *file;if((filefopen(student.txt,w))NULL){printf(open error);exit(0);}struct student *phead;while(p!NULL){fprintf(file,%s %s %d %d,p-num,p-name,p-score1,p-score2);pp-next;}fclose(file);
}