#include<stdio.h>
#include<string.h>
void main()
{
char name[20],number[20];
float math,english,computer;
double aver;
printf("Please input student's name:");
gets(name);;
printf("Please input student's number:");
gets(number);
printf("Please input student's English score:");
scanf("%f",&english);
printf("Please input student's Math score:");
scanf("%f",&math);
printf("Please input student's Computer score:");
scanf("%f",&computer);
aver=(english+math+computer)/3;
printf("Name:%s\n",name);
printf("Number:%s\n",number);
printf("Score:%5.2f\n",aver);
}
输入:
Please input student's name:Lihua
Please input student's number:123456789
Please input student's English score:80.5
Please input student's Math score:91
Please input student's Computer score:89.5
输出:
Name:Lihua
NUmber:123456789
Score:87.00
#include<iostream.h>
struct student
{
char name[20];
int num;
double english;
double math;
double computer;
double av;
};
void main()
{
student stu;
cout<<"请输入学生基本信息:"<<endl<<"姓名 学号 英语 数学 计算机"<<endl;
cin>>stu.name>>stu.num>>stu.english>>stu.math>>stu.computer;
stu.av=(stu.english+stu.math+stu.computer)/3;
cout<<"姓名 学号 平均成绩"<<endl;
cout<<stu.name<<'\t'<<stu.num<<'\t'<<stu.av<<endl;
}