输出分数在80分及以上的学生的姓名和学号

输出分数在80分及以上的学生的姓名和学号,第1张

【C语言代码】

#include 
#include 

struct stu{
	char name[10];
	char no[12];
	int score;
};
struct stu x;

int main() {
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		scanf("%s %s %d",&x.name,&x.no,&x.score);
		if(x.score>=80) printf("%s %s\n",x.name,x.no);
	}
		
	return 0;
}


/*
input:
3
Tom 12345 81
Jack 12006 78
Mary 08252 97

output:
Tom 12345
Mary 08252
*/


【C语言代码分析】

(1)请注意C语言中结构体的定义及使用方法。


struct stu{
	char name[10];
	char no[12];
	int score;
};
struct stu x;

(2)C语言中没有字符串变量,只有字符变量。


所以要输出字符串,可通过下面代码实现。


char str[12];
printf("%s",str);

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/607312.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-14
下一篇 2022-04-14

发表评论

登录后才能评论

评论列表(0条)

保存