My Profile

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

Monday, 15 August 2011

Implement the Concept of Structure

Write a Program in C to Implement the Concept of Structure
#include<stdio.h>
#include<conio.h>
struct student //Declaring a Structure of type "student"
{
int roll;
char name;
float maths;
};
void main()
{
struct student s1,s2; //Declaring Variable of type "student"

double stud_avg;
clrscr();
printf("Enter information for 1st student\n");
printf("\nRoll Number\n");
scanf("%d",&s1.roll);
printf("\nFirst character of name\n");
scanf(" %c",&s1.name);
printf("\nMarks for Maths\n");
scanf("%f",&s1.maths);
printf("\n\nEnter information for 2nd student\n");
printf("\nRoll Number\n");
scanf("%d",&s2.roll);
printf("\nFirst character of name\n");
scanf(" %c",&s2.name);
printf("\nMarks for Maths\n");
scanf("%f",&s2.maths);
printf("\n\nRoll Number \t Names \t\t Marks\n\n");
printf(" %d \t %c \t\t %.2f\n",s1.roll,s1.name,s1.maths);
printf(" %d \t %c \t\t %.2f\n",s2.roll,s2.name,s2.maths);
stud_avg=(s1.maths+s2.maths)/2;
printf("\n\nAverage of both students is %.3lf\n",stud_avg);
getch();
}

No comments:

Post a Comment

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