- 1
Write a program to store student roll no , percentage ,name using c and sort based on percentage and print
8 Antworten
+ 1
Where's your attempt? did you give it a try? or ...
+ 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/
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);
	}
}
0
But it wasn't working..there is no built error
0
But why ?



