18. write C program to store the information about three students


Program to store the information about three students.

Source Code: 

#include <stdio.h>
struct student {
    char Name[50];
    int roll;
    float marks[3];
} s[3];

int main() {
    int i;
    printf("Enter information of students:\n");
    for (i = 0; i < 3; ++i) {
        s[i].roll = i + 1;
        printf("\nFor roll number%d,\n", s[i].roll);
        printf("Enter name: ");
        scanf("%s", s[i].Name);
        printf("Enter 3 subjects marks: ");
   for (int j = 0; j < 3; j++) {
               scanf("%f", &s[i].marks[j]);
    }
    }
    printf("Displaying Information:\n\n");
    for (i = 0; i < 3; ++i) {
        printf("\nRoll number: %d\n", i + 1);
        printf("First name: \n");
        puts(s[i].Name);
        for (int j = 0; j < 3; j++) {
        printf("Marks: %.1f\n", s[i].marks[j]);
}
        printf("\n");
    }
    return 0;
}

Output:

Enter information of students:

For roll number1,
Enter name: abc
Enter 3 subjects marks: 98
96
95
For roll number2,
Enter name: xyz
Enter 3 subjects marks: 95
99
98
For roll number2,
Enter name: xyz
Enter 3 subjects marks: 90
96
93
For roll number3,
Enter name: pqr
Enter 3 subjects marks: 89
90
91

Displaying Information:
 
Roll number: 1 
First name:abc
Marks:  
98
96
95
Roll number: 2
First name:xyz
Marks:  
90
96
93

 
Roll number: 3
First name:pqr
Marks:  
89
90
91
  

No comments:

Post a Comment