My Profile

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

Monday, 15 August 2011

Print the Data and its Corresponding Memory Addresses

Write a Program in C to Accept Roll Number, Name and Marks from User for Two Students and Print the Data and its Corresponding Memory Addresses. Use Structures
 
#include<stdio.h>
#include<conio.h>
struct student //Structure
{
int roll;
char name;
float maths;
};
void main()
{
struct student s1,s2; //Elements of Structure
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\nInformation for 1st Student\n\n");
printf("Roll : %d at %u\n",s1.roll,&s1.roll);
printf("Name : %c at %u\n",s1.name,&s1.name);
printf("Marks : %.2f at %u\n",s1.maths,&s1.maths);
printf("\n\nInformation for 2nd Student\n\n");
printf("Roll : %d at %u\n",s2.roll,&s2.roll);
printf("Name : %c at %u\n",s2.name,&s2.name);
printf("Marks : %.2f at %u\n",s2.maths,&s2.maths);
stud_avg=(s1.maths+s2.maths)/2;
printf("\n\nAverage : %.2lf at %u \n",stud_avg,&stud_avg);
getch();
}

No comments:

Post a Comment

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