用C语言: 编写一个函数print,打印一个学生的成绩信息。C语言新手,求大神帮助呀,程序不知道哪里错了。

作者&投稿:连莺 (若有异议请与网页底部的电邮联系)
c语言题目,求助大神,需求程序<( ̄ˇ ̄)/~ 编写一个函数print,打印一个学生的成绩数组,该~

下面的程序先输入五位同学的数据记录,包括姓名、学号、三门课程的成绩。然后再输出这五位同学的数据记录。我想应该符合你的要求。
#include#include#include#define N 5struct stu{int grade[3];char name[10];int num;};void f_print(struct stu * temp);int main(){struct stu s[N];int i;int j;for(i=0;iname);printf("%d student number is:%d
",i+1,temp->num);for(j=0;jgrade[j]);}temp++;}}运行结果如下,也可以自己跑一下程序,就看到结果了。

#include "stdio.h"
#include
#define SIZE 50

struct student{
char num[20];
char name[20];
int score[3];
} stud[SIZE];

void print() /* 输出学生的信息 */
{
int i;
printf("
");
for(i=0;i<SIZE;i++)
printf("%s %s %d %d %d
",stud[i].num,stud[i].name,stud[i].score[0],stud[i].score[1],stud[i].score[2]);

#include <stdio.h>
struct Sudent
{
 char num[6]; //改类型
 char name[8];
 char score[4];
}stu[5];
// print 定义可以放前面
void print( struct Sudent stu[],int count)  //加上函数类型,参数类型声明
// struct student stu[6];//这句不要
{
int i,j; //增加
for(i = 0;i< count;i++) //增加
{
 printf("%s%s",stu[i].num,stu[i].name/*,stu[i].score*/);//
 for(j=0;j<3;j++)
   printf("%d",stu[i].score[j]);
  printf("
");
 }
}
//
void main()
{
 int i,j;
 //char stu[5]; //已经声明stu为全局结构体数组了,这句不要
// char print(char stu); // 
 for(i=0;i<5;i++)
 {
  scanf("%s",stu[i].num);
  scanf("%s",stu[i].name);
  for(j=0;j<3;j++)
   scanf("%d",&stu[i].score[j]);
 }
 print(stu,5);
}


for(i=0;i<5;i++)
{
scanf("%s",stu[i].num);
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
scanf("%d",&stu[i].score[j]);
}

num这个是int数组,不能用%s。只能循环一个一个输入
score这个是字符型,用%c

结构声明使用有点乱,和题目也不符合。
print函数定义也有问题。这个编译时就会报错的。
建议先想清楚结构内容,print函数,主函数内输入问题。


蒲江县19795311097: 用C语言编写一个输出考生链表的函数print()
厨人呼舒丽:void print(List *p) { Node *h; h = p; while(h->next != null) { printf("%d",h->data); h=h->Next; } }

蒲江县19795311097: 编写一个函数print(),打印学生的成绩数组,该数组记录每个学生的数据,每个记录包括 -
厨人呼舒丽: #include "stdio.h" #include <stdlib.h> #define SIZE 50struct student{char num[20];char name[20];int score[3]; } stud[SIZE];void print() /* 输出学生的信息 */ {int i;printf("\n");for(i=0;i<SIZE;i++)printf("%s %s %d %d %d\n",stud[i]....

蒲江县19795311097: c语言print函数输出格式? -
厨人呼舒丽: printf后面的参数包括“格式控制字符串”和输出变量的列表“格式控制字符串”由格式控制字符和普通字符.其中前者以%开始加某一个特殊字符.比如%d为输出整数、%c输出字符.普通字符是原样输出的内容. 输出变量列表即为输出的变量,其个数要与控制字符相对于.比如有int a=3,b=4,然后pritf(“a=%d,b=%d”,a,b);输出结果为a=3,b=4.所以printf("abc")中abc为格式控制字符串中的普通字符,原样输出. print(“%d”,i)为以整形输出变量i的值.至于具体的格式控制字符都包括什么可以查看相关书籍.

蒲江县19795311097: 编写函数print( n ),输出如下类型的图形.在主函数输入行数n,然后调用print( n )函数输出图形. -
厨人呼舒丽: #include <stdio.h> #include <conio.h>/*打印n行菱形*/ void print (int n) {int i, j; if (n<3) { /*至少得3行才能体现出图案*/printf ("至少3行才能体现出图案!\n");return;} if (n%2==0) { /*菱形必须为奇数行*/printf ("菱形图案必须为奇数行!...

蒲江县19795311097: 请问高手,在C 语言中printf与print两个有什么区别,功能上有什么不同? -
厨人呼舒丽: print--是函数,可以返回一个值,只能有一个参数.用起来最简单printf--函数,把文字格式化以后输出,直接调用系统调用进行IO的,他是非缓冲的. 如: $name="hunte"; $age=25; printf("my name is %s, age %d", $name, $age);

蒲江县19795311097: C语言:编写一个输出考生链表的函数print() -
厨人呼舒丽: // PList.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "stdlib.h" struct node { int data; struct node *next; }; int initList(node *h) {h->next=NULL; return 1; } int creatList(node *h) { node *p,*s; int x; p=h; for(int i...

蒲江县19795311097: 用c语言编写一个函数,按照给定的行数打印菱形图案 -
厨人呼舒丽: #include <stdio.h> void print(int k) {int i,j,n;n = k/2+1; for(i = 0;i<n;i++){for(j=0;j<n-i; j ++)putchar(' ');for(j = 0; j<2*i+1; j++)putchar('*');putchar('\n');}for(i = n-2; i>=0; i --){for(j=0;j<n-i; j ++)putchar(' ');for(j = 0; j<2*i+1; j++)putchar('*');...

蒲江县19795311097: c语言 题目是编写一个函数print,输出一个学生的数据记录,一共有n个学生的数据记录,每个记录包 -
厨人呼舒丽: 我只想说,呵呵.如果你们老师是这样教你们写代码.我也想对你们老师说呵呵. 在你这乱七八糟的代码基础上,把结构体的name改成数组即可.改成 char name[100];

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网