C PROGRAM TO SORT MARKS OF STUDENTS WITH THEIR NAMES USING FUNCTION
/** c program to sort the marks of the students with their names using function **/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#include<stdio.h> #include<conio.h> #include<string.h> #define MAX 100 //maximum size of array int sortArray(int); //FUNCTION DECLARATION char Names[MAX][25]; //maximum int array[MAX],new[MAX]; int main() { int i,size,temp1; printf("\n>>>> PROGRAM TO SORT ARRAY WITH NAMES USING FUNCTION <<<<\n\n"); printf("\n Enter the Number of Students: "); scanf("%d",&size); // reading number of students from user if(size>100) //checks if size of array greater than 100 { printf("\n size sholud not be more than 100 \n"); return; //terminates the program execution } printf("\n Enter the Names of %d Students: \n",size); for(i=0;i<size;i++) //loop for reading names of students { printf("\n Names[%d]: ",i+1); scanf("%s",Names[i]); } printf("\n Enter the Marks Of Each Student: \n"); for(i=0;i<size;i++) //loop for reading marks of each student { printf("\n %s: ",Names[i]); scanf("%d", &array[i]); } sortArray(size); //calling function printf("\n The Sorted elements of array are:\n"); for(i=0;i<size;i++) { temp1=new[i+1]; printf("\n %s : %d\n-------------",Names[i],array[i]); } getch(); return 0; } sortArray(n) //function for sorting { int temp=0,i,j; //temp var is temporary variable for sorting char str[MAX]; //temporary string for sorting.. for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(array[i]>array[j]) { //swapping names and numbers for sorting temp=array[i]; strcpy(str,Names[i]); array[i]= array[j]; strcpy(Names[i],Names[j]); array[j]=temp; strcpy(Names[j],str); } } } } |
Output: ( using GNU GCC Compiler with code::blocks IDE)
output 1: (here the output of the program after entering all values)
output 2: (output to show if the size > 100)
@mozart : for getting image of output window take the screen shot and u can save as a image using paint software .
It will be very helpful if you say how to copy the output window as a jpeg image…It will be helpful to my assignment….Anticipating a promt reply..and thanks in advance