- 1

Write a program to store student roll no , percentage ,name using c and sort based on percentage and print

7th Oct 2021, 6:37 AM
Sumit Acharya
Sumit Acharya - avatar
8 ответов
+ 1
Where's your attempt? did you give it a try? or ...
7th Oct 2021, 7:51 AM
Ipang
+ 1
Do you have to do the sorting by your own code? I would suggest you to use qsort() from <stdlib.h> http://www.cplusplus.com/reference/cstdlib/qsort/
7th Oct 2021, 8:00 AM
Ipang
0
#include <stdio.h> struct student { int roll; float percent; char name[20]; } s[100], temp; void main() { int i, j, n; printf("enter the no. of students: " ); scanf_s("%d", &n); for (i = 0; i < n; i++) { printf("\nstudent's Roll Number: "); scanf_s("%d", &s[i].roll); printf("\nstudent's Name: "); scanf_s("%s", &s[i].name); printf("\nStudent's percentage: "); scanf_s("%f", &s[i].percent); } for (i = 0; i < n; i++) { printf("\nROLL_NUMBER\tNAME\tPERCENTAGE\n\n\n"); printf("%d", s[i].roll); printf("\t%s", s[i].name); printf("\t%.1f", s[i].percent); } for (i = 0; i < n; i++) { for (j = 0; j < n - i - 1; j++) { if (s[j].percent < s[j + 1].percent) { temp = s[j]; s[j] = s[j + 1]; s[j + 1] = temp; } } } printf("In order"); printf("\nROLL_NUMBER\tNAME\tPERCENTAGE\n\n\n"); for (i = 0; i < n; i++) { printf("%d", s[i].roll); printf("\t%s", s[i].name); printf("\t%.1f", s[i].percent); } }
7th Oct 2021, 7:54 AM
Sumit Acharya
Sumit Acharya - avatar
0
But it wasn't working..there is no built error
7th Oct 2021, 7:55 AM
Sumit Acharya
Sumit Acharya - avatar
0
But why ?
7th Oct 2021, 7:55 PM
🌀 Shail Murtaza شعیل مرتضیٰ
🌀 Shail Murtaza شعیل مرتضیٰ - avatar