#include<stdio.h> #include<conio.h> //structure declaration struct student { char name[15]; float marks_sub1; float marks_sub2; float marks_sub3; float average; }; //user defined function declaration void setData(student* temp); void calcAvg(student* temp); void printData(student* temp); //main function void main() { int i; //declare an array of student type variables student s[5]; for( i=0;i<5;i++ ) { printf("\nenter the student %d details",i); //set data collects the student information setData(&s[i]); //calculates the average calcAvg(&s[i]); } for( i=0;i<5;i++ ) { printf("\nstudent %d details",i); //call print data to print the student details printData(&s[i]); } getch(); } //function to print data void printData(student* temp) { printf("\n\n***************************************"); printf("\nname:%s",temp->name); printf("\nsubject1 marks:%f",temp->marks_sub1); printf("\nsubject2 marks:%f",temp->marks_sub2); printf("\nsubject3 marks:%f",temp->marks_sub3); printf("\nAverage marks:%f",temp->average); printf("\n**************************************"); } //this function calculates the average void calcAvg(student* temp) { temp->average=(temp->marks_sub1+temp->marks_sub2+temp->marks_sub3)/3; } //this function collects the input data void setData(student* temp) { printf("\nenter the name:"); scanf("%s",temp->name); printf("\n enter the subject1 marks:"); scanf("%f",&temp->marks_sub1); printf("\n enter the subject2 marks:"); scanf("%f",&temp->marks_sub2); printf("\n enter the subject3 marks:"); scanf("%f",&temp->marks_sub3); }
Wednesday, 4 April 2012
C program using Structures to read and display Student details
Labels:
C
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment