DO NOT MISS

Ads

Wednesday, 21 December 2016

C-Programs Using Structures with in Structures


Structures with in a structures means nesting structures. Nesting of structures is permitted in C-Language.

Example:-
 

#include<stdio.h>
#include<conio.h>

struct dob
   {
       int day;
       char month[10];
       int year;
   }d; 


struct student
   {
       int no;
       char name[10];
       struct dob d;
   }std;


void main()
   {
       struct student std;
       clrscr();

       printf("Enter student no: ");
       scanf("%d",&std.no);
 
       printf("Enter student name: ");
       scanf("%s",&std.name);

       printf("Enter day value: ");
       scanf("%d",&std.d.day);

       printf("Enter month name: ");
       scanf("%s",&std.d.month);

       printf("Enter year value: ");
       scanf("%d",&std.d.year);

       printf("\n\nStudent no=%d\n",std.no);
       printf("stuudent name=%s\n",std.name);

       printf("Date of Birth:%d-%s-%d",
       std.d.day,std.d.month, std.d.year);


    getch();

  }

Output:-


---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------


Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims