Created
April 7, 2016 09:37
-
-
Save dsouzadyn/643ef5deb311add5c3aed8a637afd0ed to your computer and use it in GitHub Desktop.
Student Record Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define MAX 10 | |
struct date { | |
int year; | |
int month; | |
int date; | |
}; | |
struct Student_record { | |
char name[128]; | |
int roll_number; | |
struct date date_of_birth; | |
float s[5]; | |
float total; | |
}; | |
void print_record(struct Student_record); | |
void print_rank_wise(struct Student_record []); | |
void print_roll_number_wise(struct Student_record []); | |
int main() { | |
int i,j; | |
struct Student_record sr[MAX]; | |
for(i = 0; i < MAX; i++) { | |
printf("Enter name: "); | |
scanf("%s", sr[i].name); | |
printf("Enter roll number: "); | |
scanf("%d", &sr[i].roll_number); | |
printf("Enter DOB in DD MM YYYY format: "); | |
scanf("%d %d %d", &sr[i].date_of_birth.date, &sr[i].date_of_birth.month, &sr[i].date_of_birth.year); | |
printf("Enter marks :"); | |
sr[i].total = 0; | |
for(j = 0; j < 5; j++) { | |
scanf("%f", &sr[i].s[j]); | |
sr[i].total += sr[i].s[j]; | |
} | |
} | |
print_rank_wise(sr); | |
print_roll_number_wise(sr); | |
return 0; | |
} | |
void print_record(struct Student_record x) { | |
printf("%20s %3d %2d - %2d - %4d %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n", | |
x.name, | |
x.roll_number, | |
x.date_of_birth.date, | |
x.date_of_birth.month, | |
x.date_of_birth.year, | |
x.s[0], | |
x.s[1], | |
x.s[2], | |
x.s[3], | |
x.s[4], | |
x.total); | |
} | |
void print_rank_wise(struct Student_record x[MAX]) { | |
int i,j; | |
for(i = 0; i < MAX; i++) { | |
for(j = i+1; j < MAX; j++) { | |
if(x[i].total < x[j].total) { | |
struct Student_record t = x[j]; | |
x[j] = x[i]; | |
x[i] = t; | |
} | |
} | |
} | |
for(i = 0; i < MAX; i++) | |
print_record(x[i]); | |
} | |
void print_roll_number_wise(struct Student_record x[MAX]) { | |
int i, j; | |
for(i = 0 ; i < MAX; i++) { | |
for(j = i+1; j < MAX; j++) { | |
if(x[i].roll_number > x[j].roll_number) { | |
struct Student_record t = x[j]; | |
x[j] = x[i]; | |
x[i] = t; | |
} | |
} | |
} | |
for(i = 0; i < MAX; i++) | |
print_record(x[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment