c语言结构体复习

#define _CRT_SECURE_NO_WARNINGS

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


struct students
{
	char name[21];
	unsigned int age;
	char tel[16];
	float scores[3];
	char sex;

}stu;

 
int main1(void)
{

	char arr[10] = "abc";

	//struct  students stu = { "aaa", 20, "13111111111", 100.0f, 200, 300, 'M' };
	//struct  students stu = { .name = "aaa", .age = 20, .tel = "13111111111", .scores[0] = 100.0f, .scores[1] = 200, .scores[2] = 300, .sex= 'M' };

	struct students stu1;
	//stu.name = "奸恶蝌蚪";
	strcpy(stu.name, "奸恶蝌蚪");
	stu.age = 25;
	strcpy(stu.tel, "13111111111");
	stu.scores[0] = 90;
	stu.scores[1] = 91;
	stu.scores[2] = 92;
	stu.sex = 'M';

	printf("姓名:%s\n", stu.name);
	printf("年龄;%d\n", stu.age);
	printf("电话:%s\n", stu.tel);
	printf("成绩:%.1f, %.1f,%f\n", stu.scores[0], stu.scores[1], stu.scores[2]);
	printf("性别:%s\n", stu.sex == 'M' ? "男":"女");
	
	/*
	姓名:aaa
年龄;20
电话:13111111111
成绩:100.0, 200.0,300.000000
性别:女
请按任意键继续. . .
*/


	system("pause");
	return EXIT_SUCCESS;
}
#define _CRT_SECURE_NO_WARNINGS

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


struct stu1
{
	char  name[21];
	float scores[3];


};


int main2(void)
{

	struct stu1 s[3];

	for (int i = 0; i < 3; i++)
	{
		printf("请输入学生姓名 成绩 \n");
		scanf("%s%f%f%f", s[i].name, &s[i].scores[0], &s[i].scores[1], &s[i].scores[2]);
	}


	for (int i = 0; i < 3; i++)
	{
		printf("排序前%s %.1f %.1f %.1f\n", s[i].name, s[i].scores[0], s[i].scores[1], s[i].scores[2]);
	}


	/*
	请输入学生姓名 成绩
a 10 20 30
请输入学生姓名 成绩
a1 20 30 40
请输入学生姓名 成绩
a2 30 40 50
a 10.0 20.0 30.0
a1 20.0 30.0 40.0
a2 30.0 40.0 50.0
请按任意键继续. . .
*/
	for (int i = 0; i < 3-1; i++)
	{
		for (int j = 0; j < 3 - i - 1; j++)
		{
			int sum1 = s[j].scores[0] 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值