网站建设分辨率,泰安口碑好的企业建站公司,做推广用的网站,wordpress 管理插件1.编写函数 int delarr(int a[] ,int n)#xff0c;删除有n个元素的正整型数组a中所有素数#xff0c;要求#xff1a; 1#xff09;数组a中剩余元素保持原来次序#xff1b; 2#xff09;将处理后的数组输出#xff1b; 3#xff09;函数值返回剩余元素个数#xff1…1.编写函数 int delarr(int a[] ,int n)删除有n个元素的正整型数组a中所有素数要求 1数组a中剩余元素保持原来次序 2将处理后的数组输出 3函数值返回剩余元素个数 4不能额外定义新数组。
#include stdio.hint prime(int n) {if(n1)return 0;for(int i2; in/2; i)if(n%i0)return 0;return 1;
}int delarr(int a[],int n) {for(int i0; in; i) {if(prime(i)) {for(int ji; jn-1; j)a[j]a[j1];i--;n--;}}for(int i0; in; i)printf(%4d,a[i]);return n;
}
2.编写函数bool cmpstr(char *s),判定一个给定字符串s是否对称对称字符串也成为回文是满足从左到右和从右到左均相同的字符序列不考虑默认字符串结尾’\0’
#include stdio.h
#include stdbool.hbool cmpstr(char *s) {int count0;while(s[count]!\0)count;int low0,highnum-1;while(lowhigh) {if(s[low]!s[high])return false;low;high--;}return true;
}
3.编写递归函数float comp(float a[],int n)计算给定n个元素的float型数组中所有元素的算术平均值。
#include stdio.hfloat comp(float a[],int n) {if(n1)return a[0];return (a[n-1](n-1)comp(a,n-1))/n;
}
4.每个学生的信息卡片包括学号、姓名、年龄三项。定义存储学生信息的单向链表的节点类型编写函数由键盘依次输入n个学生的信息创建一个用于管理学生信息的单向链表。
#include stdio.h
#include stdlib.htypedef struct student {int id;char name[10];int age;struct student *next;
} student;struct student *create(int n) {struct student *headNULL,*p1,*p2;for(int i0; in; i) {p1(struct student *)malloc(sizeof(struct student));scanf(%d%s%d,(p1-id),(p1-name),(p1-age));if(i0)headp1;elsep2-nextp1;p2p1;}p2-nextNULL;return head;
}
5.编写函数把上中创建的单向链表中所有年龄为z的结点删除z的指由用户键盘输入且年龄为z的结点可能有多个将处理后的单向链表的所有学生信息存储到名为output.txt的文本文件中。
#include stdio.h
#include stdlib.htypedef struct student {int id;char name[10];int age;struct student *next;
} student;void save(struct student *head,int z) {FILE *file;if((filefopen(output.txt,w))NULL) {printf(open error);exit(0);}while(head!NULLhead-agez)headhead-next;struct student *phead,*qNULL;while(p!NULL) {if(p-age!z)qp;elseq-nextp-next;pp-next;}while(head!NULL) {fprintf(file,%5d\n%10s%5d\n,head-id,head-name,head-age);headhead-next;}fclose(file);
}