#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "alloc.h"
#include "math.h"
struct grade
{
float subject[5];
float total;
};
struct students
{
char name[30];
int roll_no;
struct grade marks;
};
void read_data (struct students *);
void print_data (struct students s[]);
void sort_list (struct students s[]);
void swap (struct students * , struct students *);
int i,j,N; /* Global declaration for Index i and j and
N: Total number of students */
void main()
{
/* double d=sin(0.0); if the program generates error like "floating point format not linked"
include the above given statement */
clrscr();
struct students *s;
printf("How many students are there? ");
scanf("%d",&N);
s=(struct students *) malloc(N*sizeof(struct students));
printf("\n*******ENTER DATA*******");
for(i=0;i
printf("\nName: ");
scanf("%[^\n]",s->name);
printf("Roll No: ");
scanf("%d",&s->roll_no);
printf("\nEnter The Marks Of Following Subjects.\n\n");
for(i=0;i<5;i++)
{
printf("Subject %d: ",i+1);
scanf("%f",&s->marks.subject[i]);
s->marks.total+=s->marks.subject[i];
}
}
/* Sorting the list in Descending order */
void sort_list(struct students a[])
{
for(i=0;i
if((a+j)->marks.total>(a+j-1)->marks.total)
swap(a+j,a+j-1);
}
/* This function Swaps the contents of s1 and s2 i.e,
- Total Marks
- Mark of Individual Subjects
- Roll Number and
- Name
*/
void swap(struct students *s1,struct students *s2)
{
int temp;
char string[30];
temp=s1->marks.total;
s1->marks.total=s2->marks.total;
s2->marks.total=temp;
for(i=0;i<5;i++)
{
temp=s1->marks.subject[i];
s1->marks.subject[i]=s2->marks.subject[i];
s2->marks.subject[i]=temp;
}
temp=s1->roll_no;
s1->roll_no=s2->roll_no;
s2->roll_no=temp;
strcpy(string,s1->name);
strcpy(s1->name,s2->name);
strcpy(s2->name,string);
}
/* Printing Data */
void print_data(struct students a[])
{
printf("Record Of The Students Rankwise.");
for(i=0;i
printf("\nRoll No: %d\n",(a+i)->roll_no);
printf("\n--------------------------------MARKS-------------------------------------\n");
printf(" Math C-Programming Com.Concept Physics English Total\n");
for(i=0;i<5;i++)
printf("%-12.2f ",(a+i)->marks.subject[i]);
printf("%-12.2f",(a+i)->marks.total);
getch();
}
}
/* END OF PROGRAM */
Friday, June 26, 2009
Program To Input The Records Of N Students And Display Rankwise.
Labels: Small Projects
Posted by Unknown at 12:42 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment