Thank you for your info Adak. I am the beginners in C programming and not familiar with structure and pointer.
Here are my coding which i do swap function on studentMark to get ascending order for studentMark.
Unfortunately, the studentName is not swap together. Are there any suggestion on how structure can help me to sorting studentName and studentMark together?
Code:
#include<stdio.h>
#include<conio.h>
main()
{
char studentName[10][31]; //store up to 10 names with
//maximum length for name up to 30 characters.
float studentMark[10];
int i,j,hold;
for(i=0; i<10; i++)
{
printf("Enter name for student #%d", i+1);
scanf("%s", studentName[i]);
printf("Enter mark for student #%d", i+1);
scanf("%f", &studentMark[i]);
}
for (i=0;i<=10-1;i++)
for (j=0; j<=10-2; j++)
{
if (studentMark[j]>studentMark[j+1])
{
hold=studentMark[j];
studentMark[j] = studentMark[j+1];
studentMark[j+1] = hold;
}
}
printf("\n List of student in ascending order\n");
for (i=0; i<10; i++)
{
printf("%s\t\t%.0f\n", studentName[i], studentMark[i]);
}
getch();
return 0;
}