Hello, i am currently working on the Flapjacks problem, The program compiles correctly, only it keeps going into infinity when i input, it keeps asking for more inputs, and its supposed to stop when i input -1.
Here is my Code.
#include <stdio.h>
#define SIZE 30
int isinorder (int []);
void flip (int [], int, int);
int main ()
{
int j, size, S[20], i, largest_position, largest, start, counter = 0;
while (size > 0)
{
scanf ("%d", &size);
for (j = 0; j < size; j++)
{
scanf ("%d", &S[j]);
}
}
while (!isinorder (S))
{
counter = SIZE;
largest = 0;
for (i = 0; i = counter; i++)
{
if (S[i] > largest)
{
largest_position = i;
largest = S[i];
}
}
}
flip (S, start, largest_position);
flip (S, start, counter);
for (i = 1; i <= counter; i++)
{
printf ("%d ", &i);
}
printf ("0\n");
}
int isinorder (int S[])
{
int i;
for (i = 1; i < SIZE; i++)
{
if (S[i - 1] > S[i])
return 0;
}
return 1;
}void flip (int S[], int start, int largest_position)
{
int i, temp;
start = 0;
for (i = start; i < (largest_position - start)/2; i++)
{
temp = S[i];
S[i] = S [largest_position - i];
S [largest_position - i] = temp;
}
}