C语言程序设计实验报告 C语言程序设计实验报告完整版

作者&投稿:蛮昏 (若有异议请与网页底部的电邮联系)
代码:

# include <stdio.h>
# include<stdlib.h>

char stu_no[10][10];
int c_math[10],c_en[10],c_computer[10],point[10],average[10];
int i,j,max;
char c;

void input()
{
for(i=0;i<=9;i++) /*输入学生成绩*/
{
printf("请输入学号:");
scanf("%s",&stu_no[i]);
printf("\n请输入数学成绩:");
scanf("%d",&c_math[i]);
printf("\n请输入英语成绩:");
scanf("%d",&c_en[i]);
printf("\n请输入计算机基础成绩:");
scanf("%d",&c_computer[i]);
}
for(i=0;i<=10;i++) /*计算总分跟平均分*/
{
point[i]=c_math[i]+c_en[i]+c_computer[i];
average[i]=point[i]/3;
}

}

void paixu()
{

printf("成绩按从高到低排列为:\n");
printf("\n学号 数学 英语 计算机基础 总分 平均分\n");
for (i=0;i<=10;i++)
{ for(j=1;j<=10;j++)
if (point[i]>point[j])
max=i;
printf("%s,d,%d,%d,%d,%d,%d\n",stu_no[max],c_math[max],c_en[max],c_computer[max],point[max],average[max]);

}
}

void main()
{

input();

paixu();

}

用链表:
#include <stdio.h>
#include <stdlib.h>

#ifndef NULL
#define NULL 0
#endif

#define LEN sizeof(struct student)

struct student
{
long num;
float score;
struct student *next;
};

int n;

struct student *creat(void)
{
struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}

void print(struct student *head)
{
struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{
printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}

struct student *del(struct student *head,long num)
{
struct student *p1, *p2;
if(head==NULL){printf("\nlist null!\n");return NULL;}
p1=head;
while(num!=p1->num && p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(num==p1->num)
{
if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;
}
else printf("%ld not been found!\n",num);
return(head);
}

struct student *insert(struct student *head, struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{
while((p0->num > p1->num) && (p1->next != NULL))
{
p2=p1;
p1=p1->next;
}
if (p0->num <= p1->num)
{
if(head==p1) head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{p1->next=p0;p0->next=NULL;}
}
n=n+1;
return head;
}

void main()
{
struct student *head, *stu;
long del_num;
printf("input records:\n");
head=creat();
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
while(del_num!=0)
{
head=del(head,del_num);
print(head);
printf("\ninput the deleted record:");
scanf("%ld",&del_num);
}
printf("\ninput the inserted record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num!=0)
{
head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
}

挺好的

C语言程序设计实验报告怎么写啊~

只是个例子,不可照抄。

实验内容与要求:
[实验内容]
1、通过本试验初步培养计算机逻辑解题能力。熟练掌握赋值语句和if语句的应用;掌握switch多路分支语句和if嵌套语句的使用
2、将前期所学习到的基本数据类型、运算符和表达式等程序设计基础知识运用于具体的程序设计。
3、进一步熟练掌握输入输出函数scanf, printf和getchar的使用,熟悉math.h中常用数学函数的使用方法
4、掌握循环语句的应用方法。
5、了解随机数生成函数。

[实验要求]
在规定期限独立完成实验内容
1、提交实验报告(电子版)
2、提交相应源程序文件(文件名 EX6_x姓名.c, 如EX6_1彭健.c)
3、要求从简单到复杂,后面的要求均在前面的基础上进行修改,前六题,每题均需要保留各自的程序,六题以后,每题均在前一题基础上修改,保留最后一个程序即可(如做到第九题,则保留EX6_9姓名.c,做到第11题,则保留ex6_11姓名.c)

二、实验原理和设计方案:
1、函数头的选则,while循环语句,switch(case)语句,条件表达式,if else条件语句,自增运算符,设置复杂变量,输出随机操作数。
2、变量要有分数变量和等级变量,要有选择算法题数的变量和计算正确与否的变量,要有随机输出的两个操作数变量和自己按运算符号输入结果的变量,最后还有判断是否要进行的变量字符。中间结果有选择运算符的switch()和分数等级的switch()和错题对题的自增和选择运算符计算的自增。
3、问题的分析方法:先考虑设置整形变量和字符变量,考虑到要不断循环计算,选择用while语句来循环。在循环体中,将前面的输出提示运算符,和自行选择运算符、答案及输出随机操作数完成。再用switch语句对选择的运算符进行判断,并用变量进行自增运算,计算出错题于对题个数和选择了那种运算符号。在循环体最后用if else语句来判断是否继续执行还是跳出循环。最后根据自增计算的结果和公式进行分数计算,并用switch语句来是想等级的制定。

三、源代码
#include
#include
#include
void main()
{
..........
}

四、试验结果和启发
因为输入y要继续循环,所以选择用while语句。在while语句中要结合前面的按提示计算,并嵌套switch语句并用条件表达式,来计算结果正确与否,计算的题型是什么。最后再用switch语句来完成分数等级的判断。

五、实验体会:
描述自己在编程或程序编译运行中遇到的难点和问题及解决的办法。

这个题目很简单!

你可以把我这个程序的输出部分修改一下(不修改也可以)
程序如下:

#include

#define STU_NUM 10//学生数目
#define SCORE_NUM 3//课程数目

typedef struct /*定义结构体数组*/
{
char num[20]; /*学号*/
char name[20]; /*姓名*/
float score[SCORE_NUM]; /*成绩*/
float total;//总分
float average;//平均分
} Student;

Student stu[STU_NUM];

//输入学生信息
void input()
{
int i,j;

printf("请输入%d个学生的信息:
",STU_NUM);
for(i=0;i<STU_NUM;i++)
{
printf("学号:");
scanf("%s",stu[i].num);
printf("姓名:");
scanf("%s",stu[i].name);
for(j=0;j<SCORE_NUM;j++)
{
printf("科目%d的成绩:",j+1);
scanf("%f",&stu[i].score[j]);
}
}
}

//输出学生信息
void output(void)
{
int i,j;

for(i=0;i<STU_NUM;i++)
{
printf("学生的信息如下:
");
printf("学号:%s
",stu[i].num);
printf("姓名:%s
",stu[i].name);
for(j=0;j<SCORE_NUM;j++)
{
printf("科目%d的成绩:%f
",j+1,stu[i].score[j]);
}
printf("总分:%f
",stu[i].total);
printf("平均分:%f
",stu[i].average);
}
}

//计算总分和平均分
void process()
{
int i,j;

for(i=0;i<STU_NUM;i++)
{
stu[i].total=0;
for(j=0;j<SCORE_NUM;j++)
{
stu[i].total+=stu[i].score[j];
}
stu[i].average=stu[i].total/SCORE_NUM;
}
}

//按总分进行排序(冒泡法)
void sort()
{
Student tStu;
int i,j;

for(i=0;i<STU_NUM;i++)
{
for(j=STU_NUM-1;j>i;j--)
{
if(stu[j].total>stu[j-1].total)
{
tStu=stu[j];
stu[j]=stu[i];
stu[i]=tStu;
}
}
}
}

main()
{
input();
process();
sort();
output();
}