My Profile

I, Das ShrikKrishna J. MCA III IMSCD&R, Ahmednagar.

Monday, 15 August 2011

Implement the of Nested Structure

Write a Program in C to Implement the Concept of Nested Structure
#include<stdio.h>
#include<conio.h>
struct student_academic
{
int maths;
int science;
int english;
int total;
};
struct student_personal
{
int roll;
char name[50];
int age;
struct student_academic as; //Nested
};
 
 
void main()
{
struct student_academic as;
struct student_personal ps;
printf("Enter Roll Number\n");
scanf("%d",&ps.roll);
printf("\nEnter name\n");
scanf("%s",&ps.name);
printf("\nEnter age\n");
scanf("%d",&ps.age);
printf("\nEnter marks for Maths\n");
scanf("%d",&ps.as.maths); //nested
printf("\nEnter marks for Science\n");
scanf("%d",&ps.as.science); //nested
printf("\nEnter marks for English\n");
scanf("%d",&ps.as.english); //nested
ps.as.total=(ps.as.maths)+(ps.as.science)+(ps.as.english);
printf("\n\nRoll Number \t Name \t\t Age\n\n");
printf(" %d \t \t %s \t %d \n",ps.roll,ps.name,ps.age);
printf("\n\nMarks of Student %s\n\n",ps.name);
printf("Maths : %d\n",ps.as.maths);
printf("Science : %d\n",ps.as.science);
printf("English : %d\n",ps.as.english);
printf(" ----\n");
printf("Total : %d\n",ps.as.total);
getch();
}

No comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | cheap international calls