Example program for array of structure in C C++

Example program for array of structure in C C++

C Language में Character Array या String किसे कहते है जानने के लिए देखें हमारा यह पोस्ट— Strings in C

Function क्या है इसका प्रयोग क्यो किया जाता है यह कितने प्रकार का होता है जानने के लिए देखें—Functions in C

C Language में Structure क्या होता है और इसका प्रयोग क्यो किया जाता है जानने के लिए देखें—Structures in C

Example program for array of structure in C

#include<stdio.h>

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    struct student s[3];
    int i;
    for(i=0;i<3;i++)
    {
        printf("Enter Grade   : ");
        scanf("%c",&s[i].grade);
        printf("Enter Marks   : ");
        scanf("%d",&s[i].marks);
        printf("Enter Percent : ");
        scanf("%f",&s[i].percent);
    }
    for(i=0;i<3;i++)
    {
        printf("The Grade is  : %c",s[i].grade);
        printf("\nThe Marks is  : %d",s[i].marks);
        printf("\nThe Percent is: %f",s[i].percent);
    }

    return 0;
}

Example program for array of structure in C++

#include<iostream>
using namespace std;

struct student
{
    char grade;
    int marks;
    float percent;
};

int main()
{
    student s[3];
    int i;

    for(i=0;i<3;i++)
    {
        cout<<"Enter Grade    : ";
        cin>>s[i].grade;
        cout<<"Enter Marks    : ";
        cin>>s[i].marks;
        cout<<"Enter Percent  : ";
        cin>>s[i].percent;
    }

    for(i=0;i<3;i++)
    {
        cout<<"The Grade is   : "<<s[i].grade<<endl;
        cout<<"The Marks is   : "<<s[i].marks<<endl;
        cout<<"The Percent is : "<<s[i].percent<<endl;
    }

    return 0;
}

Output of Example program for array of structure in C C++

Example program for array of structure in C C++

Important structure example programs in C C++

  1. Declaration and initialization of structure
  2. Pointer to structure
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer