I have a program for homework that says:
Write a program that fills an integer arrar with 100 random numbers with the values from 600 to 799. Print these numbers 8 per line, skip two lines, then sort the numbers in ascending order.
My question is how can I sort the 100 random numbers in ascending order? Here's my program so far, any tips would be great help. Thanks in advance.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
int main(void)
{
int var [ 100 ];
int x=0;
int n=0, temp;
srand (time(NULL));
for (int x = 0; x < 100; x++)
{
var [ x ]=rand () % 199 + 600 ;
printf ("%10d", var [ x ]);
}
printf ("\n\n\n");
for (int x = 0; x < 100; x++)
{
if ( var[ x ] > var[ x + 1 ])
{
temp = var[ x ];
var[ x ] = var[ x + 1];
var[ x + 1 ] = temp;
n++;
}
if ( x % 10 == 0)
{
printf("%10d", var[ x ] );
}
else
{
printf("%10d", var[ x ] );
}
//printf ("%10d", var [ x ]); // printf("\n\n");
}
printf ("\n\n");
return (0);
}