Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct {
- char name[80];
- double cgpa;
- int regNo;
- } information;
- int main()
- {
- information var_students[5]; ///0.1.2.3.4
- strcpy(var_students[0].name, "Mehraj Ul Islam");
- var_students[0].cgpa = 3.85;
- var_students[0].regNo = 1001;
- strcpy(var_students[1].name, "Shawon Majid");
- var_students[1].cgpa = 3.75;
- var_students[1].regNo = 1002;
- strcpy(var_students[2].name, "Samiul Islam Mugdha");
- var_students[2].cgpa = 3.88;
- var_students[2].regNo = 1003;
- strcpy(var_students[3].name, "Promi Mojumder");
- var_students[3].cgpa = 3.98;
- var_students[3].regNo = 1004;
- strcpy(var_students[4].name, "Mohammad Ibrahim");
- var_students[4].cgpa = 4.00;
- var_students[4].regNo = 1005;
- for(int i = 0; i < 5; i++) {
- for(int j = i + 1; j < 5; j++) {
- if(var_students[i].cgpa < var_students[j].cgpa) {
- ///swap
- information temp;
- temp = var_students[i];
- var_students[i] = var_students[j];
- var_students[j] = temp;
- }
- }
- }
- for(int i = 0; i < 5; i++) {
- printf("Name: %s\n", var_students[i].name);
- printf("Registration Number: %d\n", var_students[i].regNo);
- printf("CGPA: %0.2lf\n", var_students[i].cgpa);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement