https://www.bybit.com/register?affiliate_id=38000&group_id=52135&group_type=1
[856x508] Get $90 Rewards

C Programming code for Read & Display the Structures using loops

Write a Modular C Programming code for Reading & Displaying the 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);

read(s,n);

display(s,n);
}
void read(struct student s[50], int n)
{
for(i=0;i<n;i++)
{
    printf("\nEnter Details of Student %d",i+1);
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)
{
    printf("\nThe Details of students is: ");
    printf("\n\nName\tRollNo\tMarks\n");
for(i=0;i<n;i++)
{
printf("\n%s\t%d\t%f",s[i].name,s[i].rno,s[i].marks);
}
}

OUTPUT

Enter the no. of students you want to give info: 5

Enter Details of Student 1
Enter the Name: Harish
Enter the RollNo: 567
Enter the Marks: 789

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Student 2
Enter the Name: Aniketh
Enter the RollNo: 54
Enter the Marks: 345

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Student 3
Enter the Name: Suresh
Enter the RollNo: 456
Enter the Marks: 234

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Student 4
Enter the Name: Abhi
Enter the RollNo: 460
Enter the Marks: 123

+++++++++++++++++++++++++++++++++++++++++++++++++

Enter Details of Student 5
Enter the Name: Rahul
Enter the RollNo: 45
Enter the Marks: 734

+++++++++++++++++++++++++++++++++++++++++++++++++

The Details of students is:

Name    RollNo  Marks

Harish  567     789.000000
Aniketh 54      345.000000
Suresh  456     234.000000
Abhi    460     123.000000
Rahul   45      734.000000
Process returned 0 (0x0)   execution time : 53.826 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

 

Leave a Comment