Answer to Question #229638 in C for Arup

Question #229638

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.



1
Expert's answer
2021-08-27T05:13:35-0400
#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);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS