How to sort out random numbers from smaller to greater by using C programming!

 #include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>

#include <math.h>

int main()

{

   int i, temp,sorted;

   int howMany = 10;

   int goals[howMany];

   for(i=0;i<howMany;i++){

        goals[i] = (rand()%25)+1;

   }

   printf("Original List \n");

   for (i=0;i<howMany;i++){

    printf("%d \n",goals[i]);

   }

while(1){

    sorted = 0;


    for(i=0;i<howMany;i++){

        if(goals[i]>goals[i+1]){

            int temp = goals[i];

            goals[i] = goals[i+1];

            goals[i+1] = temp;

            sorted =1;

        }

    }

    if(sorted == 0){

        break;

    }

}

        printf("\nSorted List \n");

        for(i=0;i<howMany;i++){

            printf("%d \n",goals[i]);

        }


    return 0;

}


Comments