急急急急!c语言编程题、谢谢各位大侠啦、、

2024-12-26 09:51:33
推荐回答(5个)
回答1:

#include
#include
//#include

#define NO_LENGTH 10
#define NAME_LENGTH 20
#define NO_OF_STUDENTS 30
struct StuSco
{
char m_stuNo[NO_LENGTH + 1]; //学号
char m_name[NAME_LENGTH + 1]; //姓名
double m_socre1; //成绩1
double m_socre2; //成绩2
double m_socre3; //成绩3
double m_socre4; //成绩4
double m_perSocre; //平均成绩
};

StuSco * InPutStuInfo()
{
StuSco *pNewStructs = (StuSco *)malloc(sizeof(StuSco) * NO_OF_STUDENTS);
// memset(pNewStructs, 0, sizeof(StuSco) * NO_OF_STUDENTS);
for (int i = 0; i != NO_OF_STUDENTS; ++i)
{
printf("请依次输入第 %d 个学生的学号、姓名和四项成绩(以空格分隔,回车结束):\n", i + 1);
StuSco *p = pNewStructs + i;
scanf("%s ",p->m_stuNo);
scanf("%s ",p->m_name);
double k;
scanf("%lf %lf %lf %lf", &p->m_socre1, &p->m_socre2, &p->m_socre3, &p->m_socre4);
p->m_perSocre = (p->m_socre1 + p->m_socre2 + p->m_socre3 + p->m_socre4)/4;
}
return pNewStructs;
}

void OutPutInfo(StuSco * pInfoStructs)
{
for (int i = 0; i != NO_OF_STUDENTS; ++i)
{
StuSco *p = pInfoStructs + i;
printf("第 %d 个学生的学号:%s 姓名:%s \n四项成绩:%.2lf,%.2lf,%.2lf,%.2lf \n平均成绩:%.2lf\n",\
i+1, p->m_stuNo, p->m_name, p->m_socre1, p->m_socre2, p->m_socre3, p->m_socre4, p->m_perSocre);
}
}

void ReleaseStuInfo(StuSco * pInfoStructs)
{
free(pInfoStructs);
}

int main()
{
StuSco * pInfoStructs = InPutStuInfo();
OutPutInfo(pInfoStructs);
ReleaseStuInfo(pInfoStructs);
return 0;
}
参考一下,我运行没有问题。^_^

回答2:

// 程序基本能满足要求,格式上可能需要你自己调整一下, 希望能帮到你
#include
#define STUDENT_NUM 30 //最大学生数量

// 学生记录结构体
typedef struct _tagMark
{
int ID;
char name[20];
int chengJi[4];
float average;
}Mark;

Mark studentTable[STUDENT_NUM];// 存放学生记录的全局变量

// 读入学生的记录
bool readData()
{
bool result = true;
int index = 0;
printf("Please input the record(ID name Chinese English Maths Computer):\n");
while (index < STUDENT_NUM && scanf("%d %s %d %d %d %d", &studentTable[index].ID, &studentTable[index].name, &(studentTable[index].chengJi[0]), &(studentTable[index].chengJi[1]), &(studentTable[index].chengJi[2]), &(studentTable[index].chengJi[3])))
{
studentTable[index].average = ((studentTable[index].chengJi[0] + studentTable[index].chengJi[0] + studentTable[index].chengJi[0] + studentTable[index].chengJi[0])) / 4;
index++;
}
return result;
}

// 打印学生的记录
void printData()
{
printf("ID name Chinese English Maths Computer Average\n");
for (int index = 0;index < STUDENT_NUM; ++index)
{
printf("%d %s %d %d %d %d %.1f\n", studentTable[index].ID, studentTable[index].name, (studentTable[index].chengJi[0]), (studentTable[index].chengJi[1]), (studentTable[index].chengJi[2]), (studentTable[index].chengJi[3]), studentTable[index].average);
}
}

int main()
{
if (readData())
{
printData();
}

// 等待用户输入结束程序
getchar();
getchar();
return 0;
}

回答3:

#include
#define N 3 //学生人数,自己改

struct stu
{
int no;
char name[12];
float scores[4];
float average;
};
stu stus[N]={0};

int input();
int scan();
int main()
{
printf("输入信息记录数:%d\n",input());
printf("总共信息记录数:%d\n",scan());

fflush(stdin);
getchar();
return 0;
}

int input()
{
int i;
printf("请输入学生信息:\n");
printf("请依次输入学号 姓名 四项成绩:\n");
for (i=0;i {
printf(" record%d ",i+1);
scanf("%d%s",&stus[i].no,stus[i].name);
for (int j=0;j<4;j++)
{
scanf("%f",stus[i].scores+j);
stus[i].average+=stus[i].scores[j];
}
stus[i].average/=4;
}

return i;
}
int scan()
{
int i;
printf("学号\t姓名\t四项成绩\t\t平均成绩\n");
for (i=0;i {
printf("%d\t%s\t",stus[i].no,stus[i].name);
for (int j=0;j<4;j++)
{
printf("%-5.1f",stus[i].scores[j]);
}
printf("\t%.1f",stus[i].average);
printf("\n");
}

return i;
}

回答4:

和一楼的大致一样 只是我用了动态数量输入而已
#include "stdafx.h"

struct student
{
int nId;
char szName[10];
float fLesson[4];
float fAverage;
};

bool inputRecord(struct student stu[],int nCount)
{
for (int i=0; i {
printf("please input NO.%d's id :",i+1);
scanf("%d",&stu[i].nId);

printf("please input NO.%d's name :",i+1);
scanf("%s",stu[i].szName);

printf("please input NO.%d's item1 :",i+1);
scanf("%f",&stu[i].fLesson[0]);

printf("please input NO.%d's item2 :",i+1);
scanf("%f",&stu[i].fLesson[1]);

printf("please input NO.%d's item3 :",i+1);
scanf("%f",&stu[i].fLesson[2]);

printf("please input NO.%d's item4 :",i+1);
scanf("%f",&stu[i].fLesson[3]);

float fSum = 0.00;
for (int j=0; j<4; j++)
{
fSum += stu[i].fLesson[j];
}
stu[i].fAverage = fSum/4.0f;

printf("---------------------------------\n");
}

return true;
}

void printRecord(struct student stu[],int nCount)
{
printf("==>\t学号\t姓名\t项一\t项二\t项三\t项四\t平均分\n");

for (int i=0; i {
printf("%2d\t%d\t%s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",i+1,
stu[i].nId,stu[i].szName,stu[i].fLesson[0],stu[i].fLesson[1],
stu[i].fLesson[2],stu[i].fLesson[3],stu[i].fAverage);
}
}

int main(void)
{
int nCount = 0;
printf("please input record number :");
scanf("%d",&nCount);

struct student *pstu = NULL;
pstu =(struct student *) malloc(sizeof(student)*nCount);
memset(pstu,0,sizeof(student));

inputRecord(pstu,nCount);
printRecord(pstu,nCount);

free(pstu);

return 0;
}

回答5:

#include

//添加一个求阶乘的函数(递归)
double myJC(double n)
{
if ( n <= 1 )
{
return 1;
}
else
{
return n * myJC(n-1);
}
}

//用double可以一定程度上防止溢出.
double fun(int n)
{
double rtv = 0.0;
for ( int i = n ; i >= 1 ; i-- )
{
rtv += myJC(i);
}
return rtv;
}

int main(void)
{
printf("%.0lf",fun(20));

getchar();
return 0;
}