Write a Modular C Programming code for Reading & Displaying the Array Structures by using loops
Read the number of students, read their information and display the details of the students:
CODE:
#include<stdio.h> struct student { char name[20]; int rno; float marks; }; struct student s[50]; void read(struct student s[50], int n); void display(struct student s[50], int n); int n, i; main() { printf("Enter the no. of students you want to give info: "); scanf("%d",&n); printf("\nEnter Details of Student %d",i+1); read(s,n); printf("\nThe Details of students %d is: ",i+1); display(s,n); } void read(struct student s[50], int n) { for(i=0;i<n;i++) { printf("\nEnter the Name: "); scanf("%s",&s[i].name); printf("Enter the RollNo: "); scanf("%d",&s[i].rno); printf("Enter the Marks: "); scanf("%f",&s[i].marks); printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } } void display(struct student s[50], int n) { for(i=0;i<n;i++) { printf("\nName: %s",s[i].name); printf("\nRollNo: %d",s[i].rno); printf("\nMarks: %f",s[i].marks); printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++++\n"); } }
OUTPUT
Enter the no. of students you want to give info: 3 Enter Details of Student 1 Enter the Name: fdb Enter the RollNo: 45 Enter the Marks: 63 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: fdg Enter the RollNo: 54 Enter the Marks: 7657 +++++++++++++++++++++++++++++++++++++++++++++++++ Enter the Name: ewrw Enter the RollNo: 56 Enter the Marks: 536 +++++++++++++++++++++++++++++++++++++++++++++++++ The Details of students 1 is: Name: fdb RollNo: 45 Marks: 63.000000 +++++++++++++++++++++++++++++++++++++++++++++++++ Name: fdg RollNo: 54 Marks: 7657.000000 +++++++++++++++++++++++++++++++++++++++++++++++++ Name: ewrw RollNo: 56 Marks: 536.000000 +++++++++++++++++++++++++++++++++++++++++++++++++ Process returned 0 (0x0) execution time : 19.837 s Press any key to continue.
Please find some more codes of 1D Arrays, 2D Arrays, Pointers on the below page:
Top 100+ C Programming codes – KLE Technological University