I am trying to write a program that will pring a list of random numbers from 1-100 and store them in an array. and then bubblesort them into ascending order. This is what i have so far but it is giving me a whole different set of ascending numbers after the sort. please help! this is what i got so far.
#include<stdio.h>
int main(){
int s,temp,i,j,a[20],x;
srand(time(NULL));
while (s<10)
{
s++;
printf("%d\n",rand()%100+1);
}
for(i=0;i<s;i++){
a[i]=rand()%100+1;}
//Bubble sorting algorithm
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("After sorting: \n");
for(i=0;i<s;i++)
printf(" %d\n",a[i]);
return 0;
}