I wrote a syntax for a small program that sorts numbers.
Anyway the program works well for 30 and even 40 numbers, but when I try to sort 50 numbers or more it gets stuck. It makes no sense that the syntax is to hard for the computer, and I also know that the loop is not stuck because when i try to sort 30 numbers it's ok.. so why does it get stuck? help, anyone?
Code:
#include <stdio.h>
void main()
{
double a[100] = {0};
int counter;
int input;
int b;
int c;
int f;
int x;
int t;
int m;
int r;
double temp;
input = 0;
temp = 0;
b = 0;
x = 0;
f = 0;
t = 0;
m = 0;
r = 0;
counter = 1;
c = 1;
printf("How many numbers do you want to sort?\n");
while(scanf("%d", &input) != 1)
{
fflush(stdin);
printf("Wrong Entry. Please enter a number\n");
}
while(counter <= input)
{
printf("Print No.%d\n", counter);
while(scanf("%lf", &a[b]) != 1)
{
fflush(stdin);
printf("Wrong Entry. Please enter a number\n");
}
counter++;
b++;
}
b = 0;
counter = 0;
while(counter < input - 1)
{
while(a[b] > a[c])
{
f = input;
x = input - 1;
temp = a[c];
while(f > 0)
{
a[f] = a[x];
f--;
x--;
}
a[0] = temp;
t = c;
m = c + 1;
r = c + 2;
while(t < input)
{
a[m] = a[r];
r++;
m++;
t++;
}
b = 0;
c = 1;
counter = 0;
}
b++;
c++;
counter++;
}
a[input] = '\0';
counter = 0;
b = 0;
while(counter < input)
{
if(a[b] - (int)a[b] > 0)
{
printf("%1.1f", a[b]);
}
else
{
printf("%1.0f", a[b]);
}
if(counter < input - 1)
{
printf(",");
}
b++;
counter++;
}
printf("\n");
}