Program to read and display information of a student using structure within the structure

#include<stdio.h>

    struct dob
    {
        int date;
        char month[20];
        int year;
    };

    struct student
    {
        int rno;
        char name1[80];
        char name2[80];
        int fees;
        struct dob obj;
    } stud[100];

main()
{

    int n,i;
    printf("Enter no. of students\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter roll no. of student %d\n",i+1);
        scanf("%d",&stud[i].rno);
        printf("Enter fees\n");
        scanf("%d",&stud[i].fees);
        printf("Enter first name of student %d\n",i+1);
        scanf("%s",stud[i].name1);
        printf("Enter last name of student %d\n",i+1);
        scanf("%s",stud[i].name2);
        printf("Enter dob of student %d\n",i+1);
        scanf("%d",&stud[i].obj.date);
        scanf("%s",stud[i].obj.month);
        scanf("%d",&stud[i].obj.year);

    }
    for(i=0;i<n;i++)
    {
        printf("\n\n");
        printf("Information of student %d\n",i+1);
        printf("Roll no. = %d\n",stud[i].rno);
        printf("Name = %s %s\n",stud[i].name1,stud[i].name2);
        printf("Fees = %d\n",stud[i].fees);
        printf("DOB = %d/%s/%d",stud[i].obj.date,stud[i].obj.month,stud[i].obj.year);
    }

}


14mar_1

 

Calling and Called function & Actual and formal parameters

Let us take an example:

main() //  Here main()---> Calling Function because it is calling calsum

{

int a,b,c,sum; //------> Actual Parameters

printf("Enter values of a, b & c");

scanf("%d %d %d",&a,&b,&c);

sum=calsum(a,b,c);

printf("Sum = %d",sum);

}

calsum(x,y,z) //x,y,z-----> Formal parameters, calsum ---> Called Function

{                          // because it is called by some other function

int d;

d=x+y+z;

return(d);

}