码迷,mamicode.com
首页 > 其他好文 > 详细

抄写例题作业1

时间:2017-04-09 11:31:20      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:exit   after   with   str   ret   作业   bsp   higher   res   

例9.1:

#include<stdio.h>
int main()
{struct Student       //声明结构体类型struct Student
  {
  long int num;       //以下四行为结构体的成员
  char name[20];
  char sex;
  char addr[20];
}w={01,"Yu Jinchi",M,"Beijing Road"};    //定义结构体变量a并初始化

printf("NO.:%ld\nname:%s\nsex:%C\naddress:%s\n",w.num,w.name,w.sex,w.addr);       //输出结构体所有成员,也就是学生的所有信息

return 0;
}

NO.:1
name:Yu Jinchi
sex:M
address:Beijing Road


--------------------------------
Process exited after 0.104 seconds with return value 0
请按任意键继续. . .

 

例9.2:

#include<stdio.h>
int main()
{ struct Student        //声明结构体类型  struct Student
  {
    int num;
    char name[20];
    float score;
  }student1,student2;            //定义两个结构体变量student1,student2
scanf("%d %s %f",&student1.num,student1.name,&student1.score);     //输入学生1的数据
scanf("%d %s %f",&student2.num,student2.name,&student2.score);     //输入学生1的数据

printf("The higher score is:\n");        //输出最高分

if(student1.score>student2.score)       //用if语句进行大小比较,输出分数较大者
   printf("%d %s %6.2f\n",student1.num,student1.name,student1.score);
else if(student1.score<student2.score)
   printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);
else
 {
   printf("%d %s %6.2f\n",student1.num,student1.name,student1.score);
   printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);
 }
return 0;
}

01 yujinchi 666
02 pipixia 665
The higher score is:
1 yujinchi 666.00


--------------------------------
Process exited after 53.43 seconds with return value 0
请按任意键继续. . .

 

 

抄写例题作业1

标签:exit   after   with   str   ret   作业   bsp   higher   res   

原文地址:http://www.cnblogs.com/yujinchi/p/6684038.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!