C语言 比较结构体数的元素大小,输出值前加*
#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#defineN5structstudent{charfirst_n[15]...
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 5
struct student
{
char first_n[15];
char last_n[15];
int credit;
} ;
void input()
{
int i;
for (i=0;i<N;i++)
{
printf("Enter data for NO. %d student:\n", i+1);
printf("Enter the first name:");
scanf("%s", &stu[i].first_n);
printf("Enter the last name:");
scanf("%s", &stu[i].last_n);
printf("Enter the credit:");
scanf("%d", &stu[i].credit);
}
}
void print()
{
int i;
printf("\nPrint the data for those students:\n");
for (i=0;i<N;i++)
{
printf("%d \t %s \t %s \t %d \n", i+1, stu[i].first_n, stu[i].last_n, stu[i].credit );
}
}
int main(void)
{
struct student stu[N];
input();
print();
return 0;
}
如何在这个程序上,实现比较5个人的成绩,再在最好credit的人序号(即1,2,3,4,5)前面加*
把最大得分的人前面加*
比如输出是
1 John 5
2 Daniel 4
* 3 Joe 10
不用排序的
有悬赏分的!! 展开
#include<stdio.h>
#define N 5
struct student
{
char first_n[15];
char last_n[15];
int credit;
} ;
void input()
{
int i;
for (i=0;i<N;i++)
{
printf("Enter data for NO. %d student:\n", i+1);
printf("Enter the first name:");
scanf("%s", &stu[i].first_n);
printf("Enter the last name:");
scanf("%s", &stu[i].last_n);
printf("Enter the credit:");
scanf("%d", &stu[i].credit);
}
}
void print()
{
int i;
printf("\nPrint the data for those students:\n");
for (i=0;i<N;i++)
{
printf("%d \t %s \t %s \t %d \n", i+1, stu[i].first_n, stu[i].last_n, stu[i].credit );
}
}
int main(void)
{
struct student stu[N];
input();
print();
return 0;
}
如何在这个程序上,实现比较5个人的成绩,再在最好credit的人序号(即1,2,3,4,5)前面加*
把最大得分的人前面加*
比如输出是
1 John 5
2 Daniel 4
* 3 Joe 10
不用排序的
有悬赏分的!! 展开
展开全部
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define N 5
struct student
{
char first_n[15];
char last_n[15];
int credit;
} ;
void input()
{
int i;
for (i=0;i<N;i++)
{
printf("Enter data for NO. %d student:\n", i+1);
printf("Enter the first name:");
scanf("%s", &stu[i].first_n);
printf("Enter the last name:");
scanf("%s", &stu[i].last_n);
printf("Enter the credit:");
scanf("%d", &stu[i].credit);
}
}
void print()
{
int i;
printf("\nPrint the data for those students:\n");
int mcredit = -1;
for(i=0;i<N;i++)if(stu[i].credit>mcredit)mcredit=stu[i].credit;
for (i=0;i<N;i++)
{
if(stu[i].credit == mcredit)printf("* ");
else printf(" ");
printf("%d \t %s \t %s \t %d \n", i+1, stu[i].first_n, stu[i].last_n, stu[i].credit );
}
}
int main(void)
{
struct student stu[N];
input();
print();
return 0;
}
#include<stdio.h>
#define N 5
struct student
{
char first_n[15];
char last_n[15];
int credit;
} ;
void input()
{
int i;
for (i=0;i<N;i++)
{
printf("Enter data for NO. %d student:\n", i+1);
printf("Enter the first name:");
scanf("%s", &stu[i].first_n);
printf("Enter the last name:");
scanf("%s", &stu[i].last_n);
printf("Enter the credit:");
scanf("%d", &stu[i].credit);
}
}
void print()
{
int i;
printf("\nPrint the data for those students:\n");
int mcredit = -1;
for(i=0;i<N;i++)if(stu[i].credit>mcredit)mcredit=stu[i].credit;
for (i=0;i<N;i++)
{
if(stu[i].credit == mcredit)printf("* ");
else printf(" ");
printf("%d \t %s \t %s \t %d \n", i+1, stu[i].first_n, stu[i].last_n, stu[i].credit );
}
}
int main(void)
{
struct student stu[N];
input();
print();
return 0;
}
追问
又OK了,謝謝了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询