Course Content
History of C Language
0/2
Basic Structure of C Program
0/1
Types of Errors
0/1
Language Fundamentals
0/1
Data Types and Modifiers
0/1
Programming with C Language
About Lesson

STRUCTURE ARRAYS

Array declared out any basic data type can be a member in a structure and even array of structure can also be declared.

/*Program to read and print the data for 3 students*/

#include

struct student

{

    int roll_no;

    char name[20];          //array member

    char course[20];

    int marks_obtained ;

};

void main( )

{

struct student stud[3];

int i;

printf (“Enter the student data one by one\n\n”);

for(i=0; i<3; i++)

{

printf (“Enter the roll number of student%d :”,i+1);

scanf (“%d”,&stud[i].roll_no);

printf (“Enter the name of student%d :”,i+1);

scanf (“%s”,stud[i].name);

printf (“Enter the course of student%d :”,i+1);

scanf (“%s”,stud[i].course);

printf (“Enter the marks obtained of student%d :”,i+1);

scanf (“%d”,&stud[i].marks_obtained);

printf(“\n”);

}

printf (“the data entered is as follows\n”);

for (i=0;i<3;i++)

{

printf (“The roll number of student%d is %d :\n”,i+1,stud[i].roll_no);

printf (“The name of student%d is %s :\n”,i+1,stud[i].name);

printf (“The course of student%d is %s :\n”,i+1,stud[i].course);

printf (“The marks of student%d is %d :\n”,i+1,stud[i].marks_obtained);

}

}

 

You cannot copy content of this page