Site icon DataFlair

C Program For Array of Structures

Program 1

// Program for Array of Structure in C
#include<stdio.h>
#include<conio.h>
#include<string.h>
// Structure
struct Student
{
    int rno;                   //  Member variable of Structure 
    char name[50];      //  Member variable of Structure  , Array in structure
    double per;               //  Member variable of Structure 
};struct Student S[5];   // Structure type of variable , Array of structre
void main()
{
    int i;
    fflush(0);
    for(i=0;i<5;i++)
   { 
    printf("\nEnter Roll No : ");
    scanf("%d",&S[i].rno);
    fflush(0);
    printf("\nEnter Name : ");
    scanf("%s",S[i].name);
    printf("\nEnter Percentage : ");
    scanf("%lf",&S[i].per);
   }

    printf("\n-------------Student Infromation---------------\n\n");
    printf("\nRoll No\t Name\t Percentage\n");
    for(i=0;i<5;i++)
   { 
    printf("%d",S[i].rno);
    printf("\t%s",S[i].name);
    printf("\t %.2lf",S[i].per);
    printf("\n");
   }
}

 

Exit mobile version