Showing posts with label Array within Structure. Show all posts
Showing posts with label Array within Structure. Show all posts

Saturday 30 July 2016

Array Within the Structure

Array Within the Structure


#include<stdio.h>
struct student
{
            char name[20];           
            int rollno;
            float mark[3];
};
main()
{
            struct student S[10];
            int i, n, j;
            printf("\nEnter the number of students: ");
            scanf("%d", &n);
            for(i=0; i<n; i++)
            {
                        printf("\nEnter Student %d details: ", i+1);
                        printf("\nEnter name rollno: ");
                        scanf("%s %d", S[i].name, &S[i].rollno);
                        printf("\nEnter 3 marks: ");
                        for(j=0; j<3; j++)
                                                scanf("%f", &S[i].mark[j]);
            }
            for(i = 0;i<n;i++)
            {
                        printf("\nStudent %d details: ", i+1);
                        printf("\n\tName is %s \n\tRollno is %d", S[i].name, S[i].rollno);
                        printf("\n\tMarks are: ");
                        for(j=0; j<3; j++)
                                                printf("%f  ", S[i].mark[j]);
            }

}

Output:
Enter the number of students: 2

Enter Student 1 details:
Enter name rollno: aaa 11
Enter 3 marks: 50 60 70

Enter Student 2 details:
Enter name rollno: bbb 22
Enter 3 marks: 60 70 80

Student 1 details:
        Name is aaa
        Rollno is 11
        Marks are: 50.000000    60.000000       70.000000
Student 2 details:
        Name is bbb
        Rollno is 22
        Marks are: 60.000000    70.000000       80.000000

Goto Main Content:
https://tejaswinihbhat.blogspot.in/2016/07/data-structures-15CS33-Module1.html
https://tejaswinihbhat.blogspot.in/2016/07/structures.html