Write a program to create a class to store details of a student ( name, roll and 3 subject marks ). Input details for 2 students and assign all the details of that student who is having higher average mark to a new student using friend function.
#include <stdio.h>
int main(){
char name1[30];
int rollNo1;
int total1;
float average1;
char name2[30];
int rollNo2;
int total2;
float average2;
printf("Enter name of the first student\n");
fgets(name1,30,stdin);
printf("Enter roll number\n");
scanf("%d", &rollNo1);
printf("Enter total marks of the three subjects\n");
scanf("%d", &total1);
printf("Enter name of the second student\n");
fgets(name2,30,stdin);
printf("Enter roll number\n");
scanf("%d", &rollNo2);
printf("Enter total marks of the three subjects\n");
scanf("%d", &total2);
average1=(float)total1/3;
average2=(float)total2/3;
if(average1> average2){
printf("New Student details:\n");
printf("Name is %s",name1);
printf(",Roll Number is: %d",rollNo1);
printf(",Total is: %d",total1);
printf(",Average is: %f",average1);}
else{
printf("New Student details:\n");
printf("Student 2");
printf(",Roll Number is:%d",rollNo2);
printf(",Total is:%d",total2);
printf(",Average is: %f",average2);
}
}
Comments
Leave a comment