belongs to collection: All structure C programs with examples
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include <stdio.h> struct student { char name[50]; int roll; float marks; } stud[2]; int main() { int i; printf("Enter information of students:\n"); // storing information for(i=0; i<2; ++i) { stud[i].roll = i+1; printf("\nFor roll number: %d\n",stud[i].roll); printf("Enter name: "); scanf("%s",stud[i].name); printf("Enter marks: "); scanf("%f",&stud[i].marks); printf("\n"); } printf("Displaying Information:\n\n"); // displaying information for(i=0; i<2; ++i) { printf("\nRoll number: %d\n",i+1); printf("Name: "); puts(stud[i].name); printf("Marks: %.1f",stud[i].marks); printf("\n"); } return 0; }
Enter information of students:
For roll number: 1
Enter name: john
Enter marks: 85
For roll number: 2
Enter name: Maya
Enter marks: 80
Displaying Information:
Roll number: 1
Name: john
Marks: 85.0
Roll number: 2
Name: Maya
Marks: 80.0
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter information of students:
For roll number: 1
Enter name: john
Enter marks: 85
For roll number: 2
Enter name: Maya
Enter marks: 80
Displaying Information:
Roll number: 1
Name: john
Marks: 85.0
Roll number: 2
Name: Maya
Marks: 80.0
need an explanation for this answer? contact us directly to get an explanation for this answer