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 Two Structures

Write a Modular C Programming code for Reading & Displaying the Structures by using loops

Read the 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;
}s,s1,s2;
struct student read(struct student);
void display(struct student);
main()
{

    printf("\nEnter Details of Student1: ");
    s1=read(s1);
    printf("\nEnter Details of Student2: ");
    s2=read(s2);

    printf("\nThe Details of student1 is:");
    display(s1);
    printf("\nThe Details of student2 is:");
    display(s2);

}

struct student read(struct student s)
{
  printf("\nEnter the Name: ");
    scanf("%s",&s.name);
    printf("Enter the RollNo: ");
    scanf("%d",&s.rno);
    printf("Enter the Marks: ");
    scanf("%f",&s.marks);
    printf("\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
    return(s);
}

void display(struct student s)
{

    printf("\nName: %s",s.name);
    printf("\nRollNo: %d",s.rno);
    printf("\nMarks: %f",s.marks);
    printf("\n\n+++++++++++++++++++++++++++++++++++++++++++++++++\n");
}

 

OUTPUT

Enter Details of Student1:
Enter the Name: raju
Enter the RollNo: 420
Enter the Marks: 50

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

Enter Details of Student2:
Enter the Name: dev
Enter the RollNo: 99
Enter the Marks: 90

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

The Details of student1 is:
Name: raju
RollNo: 420
Marks: 50.000000

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

The Details of student2 is:
Name: dev
RollNo: 99
Marks: 90.000000

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

Process returned 0 (0x0)   execution time : 25.410 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