成都网站建设设计

将想法与焦点和您一起共享

c语言功能函数实现代码,C语言功能函数

C语言 如何编写该程序的主函数,使实现功能?

#include "stdio.h"#include "conio.h"#include "stdlib.h"#include "string.h"#define MAXSTUDENT (1024)#define CheckData()\{\if(!studentNum)\{\printf("没有学生数据,按任意键返回……\n");\getch();\return;\}\}\int studentNum = 0;typedef struct Student{int id;int cScore;int mathScore;}Student;void ClearStudent(Student* student){memset((void*)student,0,sizeof(*student));}void ShowMainMenu(){system("cls");printf("1.增加记录\n2.计算每个学生的总成绩\n3.计算每门课程的平均成绩\n4.按座号查询学生的成绩\n5.按总分排名\n6.输出前n名的学生的成绩\n7.修改成绩\n0.退出\n");}void ShowCountScore(const Student* student){system("cls");CheckData();for(int i = 0;i studentNum;i++)printf("学生%04d的总成绩:%d\n",(student+i)-id,(student+i)-cScore+(student+i)-mathScore);printf("\n按任意键继续……");getch();}void ShowClassAvg(const Student* student){system("cls");CheckData();double sumc = 0;double summath = 0;for(int i = 0;i studentNum;i++){sumc += (student+i)-cScore;summath += (student+i)-mathScore;}printf("C语言平均成绩为:%lf\n",sumc/studentNum);printf("数学平均成绩为:%lf\n",summath/studentNum);printf("\n按任意键继续……");getch();}void AddStudent(Student* student){system("cls");if(studentNum == MAXSTUDENT){printf("人数已满,按任意键返回……\n");getch();}printf("分别录入座号、C语言成绩、数学成绩:\n");int id = 0;int cScore = 0;int mathScore = 0;scanf("%d%d%d",id,cScore,mathScore);for(int i = 0 ;i studentNum;i++)if((student+i)-id == id){printf("座号重复,按任意键返回……\n");getch();return;}(student+studentNum)-id = id;(student+studentNum)-cScore = cScore;(student+studentNum)-mathScore = mathScore;studentNum++;}void SelectFromID(const Student* student){system("cls");CheckData();printf("输入查询ID:\n");int id = 0;scanf("%d",id);printf("查询结果:\n");for(int i = 0;istudentNum;i++)if(id == (student+i)-id){printf("C语言成绩为:%d\n数学成绩为:%d\n",(student+i)-cScore,(student+i)-mathScore);break;}printf("\n按任意键继续……");getch();}void SortForCount(Student* student){system("cls");CheckData();for(int i = 0;i studentNum;i++){for(int j = studentNum -1;j i;j--)if(((student+j)-cScore+(student+j)-mathScore) ((student+j-1)-cScore+(student+j-1)-mathScore)){Student stu;stu = *(student+j);*(student+j) = *(student+j-1);*(student+j-1) = stu;}}}void SortForN(Student* student,int n){SortForCount(student);if(!studentNum)return;n = nstudentNum?studentNum:n;for(int i = 0;i n;i++)printf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)-id,(student+i)-cScore,(student+i)-mathScore,(student+i)-cScore+(student+i)-mathScore);printf("\n按任意键继续……");getch();}void UpdateScore(Student* student){system("cls");CheckData();printf("输入修改ID:\n");int id = 0;scanf("%d",id);int i = 0;for(;istudentNum;i++)if(id == (student+i)-id)break;if(i == studentNum)printf("\n查无此人,按任意键继续……");else{printf("输入欲修改的C语言成绩、数学成绩:\n");int cScore = 0;int mathScore = 0;scanf("%d%d",cScore,mathScore);(student+i)-cScore=cScore;(student+i)-mathScore = mathScore;printf("\n按任意键继续……");}getch();}void RunStudent(Student* student){while(1){ShowMainMenu();char chGet = getch();switch(chGet){case '1':AddStudent(student);break;case '2':ShowCountScore(student);break;case '3':ShowClassAvg(student);break;case '4':SelectFromID(student);break;case '5':SortForCount(student);for(int i =0;istudentNum;i++)printf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)-id,(student+i)-cScore,(student+i)-mathScore,(student+i)-cScore+(student+i)-mathScore);printf("\n按任意键继续……");getch();break;case '6':{int n = 0;printf("输入N:\n");scanf("%d",n);SortForN(student,n);}break;case '7':UpdateScore(student);break;case '0':return;default:break;}}}int main(){Student* allStudent = (Student*)malloc(MAXSTUDENT*sizeof(Student));memset((void*)allStudent,0,MAXSTUDENT*sizeof(Student));RunStudent(allStudent);return 0;}

站在用户的角度思考问题,与客户深入沟通,找到渠县网站设计与渠县网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广、域名注册、虚拟空间、企业邮箱。业务覆盖渠县地区。

c程序语言,函数,求编程实现

第三个函数

#includestdio.h

void

main()

{

int

a,b,back;

int

mulnum(int

a,int

b);

printf("请输入两个整数:");

scanf("%d%d",a,b);

back=mulnum(a,b);

if(back==1)

printf("%d

is

multiple

of

%d\n",a,b);

else

if(back==2)

printf("%d

is

multiple

of

%d\n",b,a);

else

;

}

int

mulnum(int

a,int

b)

{

double

result;

if((result=a%b)==0)

return

1;

else

if((result=b%a)==0)

return

2;

else

return

0;

}

这个函数能技能判断a是否为b的倍数,还能判断b是否为a的倍数。楼主如果不需要第二个功能,把else

if语句

去掉就行了。

c语言:编写函数实现功能,并用相应的主函数进行测试?

#includestdio.h

void delStr(char *s,char p)

{char *p1,*p2;

for(p1=p2=s;*p1;p1++)

if(*p1!=p)*p2++=*p1;

*p2='\0';

}

int main()

{char s[300],ch;

gets(s);

ch=getchar();

delStr(s,ch);

printf("%s\n",s);

return 0;

}


文章标题:c语言功能函数实现代码,C语言功能函数
文章路径:http://chengdu.cdxwcx.cn/article/hesohe.html