用函数解决实际问题c语言 用函数解决实际问题c语言编程

C语言:用分支结构或者循环结构解决一个实际问题,并通过函数调用实5楼是正确的 。第一题:A.正确就不说了 。B.main函数一般含有参数,且是实参,这部分见函数的结构,B错 。C.见函数调用之递归调用是一种特殊的嵌套调用,是某个函数调用自己 , 而不是另外一个函数,C对 。D.不解释 。E.函数参数传递里面,上述带回多个返回值,是由形参带回来的,而形参得传递地址 。另外,实参是传递数值 , E对 。故选ACDE 。第二题:ACD 。B.形式:do{循环体语句组;}while(循环继续条件); 。故而B错 。E 。见实现S=1 2 ······ n的例子,这个是循环次数不确定的 。故而E错 。其他3个是常见知识点 。故选ACD 。
C语言编程题: 随便编一个程序解决任意实际问题,要求至少调用4个函数,其他随便,最好有注释#include
stdio.h
#includeconio.h
int
sum(int
x,int
y)
{
int
z;
z=x y;
printf("z=%d",z);
return
z;
}
void
main()
{
int
a,b,s;
printf("Input
a
and
b:");
scanf("%d,%d",a,b);
s=sum(a,b);
getch();
}
改正用函数解决实际问题c语言的错误:
1.printf("z=%d",z);无%d用函数解决实际问题c语言,则不能输出z值
2.scanf("%d",a);
表示输入到a
3.用到getch();时需加头文件#includeconio.h
4.无返回值函数需加void
C语言代码:应用函数求解#includestdio.h
#define N 100
void fun(int *a,int n) { int i,k; k=a[n-1]; for ( i=n-1;i0;i-- ) a[i]=a[i-1]; a[0]=k; }
void main() { int a[N],n,m,i;
printf("请输入n: "); scanf("%d",n); if ( n=N ) n=N;
printf("请输入%d个整数: ",n); for ( i=0;in;i) scanf("%d",a[i]);
printf("请输入后移数据个数: "); scanf("%d",m);
for ( i=0;im;i) fun(a,n);
for ( i=0;in;i) printf("%d ",a[i]); printf("\n");
}
求一个用C语言解决实际问题的程序,要求用到:数组 , 循环,除主函数外自定义3个函数,用盘文件输出 。谢啦这个就可以:
咱班都看过了 。。(底下都写上?。。。∥壹堑糜懈龅胤剿虼砹耍?交之前让老师帮你改一改 。这个交上去是很多个老师一起看?。。?
1题目:学生信息管理系统
2程序要求:
学生信息录入功能
用户从键盘输入每个学生的信息:学号、姓名、性别、数学、英语、政治、语文四门课成绩 。
可插入一个或多个学生信息到当前编辑的班级数据中 。
文件保存功能
学生信息每一班存为一个数据文件 , 数据文件可在程序中打开、编辑和重新保存 。
用户输入学生信息可随时保存数据文件 。
文件打开功能
程序只能对当前打开的数据文件进行编辑 。
查询功能
浏览所有学生信息 。
按学号查询学生信息 。
按姓名查询学生信息 。
查询一个班总成绩和平均成绩 。
查询一个班某一门课总成绩和平均成绩 。
查询某一门课分数段(60,60-69,70-79 , 80-89,90)学生数 。
报表输出功能
按学号输出一个班学生信息:学号、姓名、性别、数学、英语、政治、语文成绩、总成绩,到屏幕和文件 。
按总成绩从高到低输出学号、姓名信息 。
注:以上功能以菜单形式供用户使用 , 并有一定的容错功能 。
3开发语言环境:Macrosoft VC6.0或Turbo C2.0
4数据结构:数组或链表
5程序源代码要求:
函数名、变量名采用英文缩写,使用匈牙利命名法进行自说明 。
源代码的书写采用递进格式 。
程序行和程序段须有注释 。
#include "stdio.h" /*I/O函数*/
#include "stdlib.h" /*其它说明*/
#include "string.h" /*字符串函数*/
#include "conio.h" /*屏幕操作函数*/
#include "mem.h" /*内存操作函数*/
#include "ctype.h" /*字符操作函数*/
#include "alloc.h" /*动态地址分配函数*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;
void shuru()
{
if((fp=fopen("s_score.txt","ab "))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i=1000;i)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0] data.score[1] data.score[2] data.score[3] data.score[4];
fwrite(data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb "))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i=1000;i)
{
if((fread(info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;ji;j,k)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}
void xiugai()
{
if((fp=fopen("s_score.txt","rb "))==NULL||(fp1=fopen("temp.txt","wb "))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",i); getchar();
while((fread(data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0] data.score[1] data.score[2] data.score[3] data.score[4];
} fwrite(data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(data,sizeof(data),1,fp1))==1)
{
fwrite(data,sizeof(data),1,fp);
}
fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",i);
while(fread(data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb "))==NULL||(fp1=fopen("temp.txt","wb "))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",i);getchar();
while((fread(data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1shuru 2xiugai * \n");
printf("* 3shanchu 4chazhao * \n");
printf("* 5xianshi 6exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}
}
【用函数解决实际问题c语言 用函数解决实际问题c语言编程】关于用函数解决实际问题c语言和用函数解决实际问题c语言编程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读