Sunday, 8 September 2013

C program for finding the smallest integer amongst entered values

C program for finding the smallest integer amongst entered values

I want the user to enter any integer n. In the next line, n space
separated integers will be entered. I want to find out the smallest
integer among these n integers.
#include <stdio.h>
#include <math.h>
int main(void)
{
int x, y, z, a[x], p = -1, q;
scanf ("%d", &x);
y = 0, q = 0, z = 0;
while (z <= x - 1)
{
scanf ("%d", &a[y]);
if (a[y] <= p)
p = a[y];
y = y + 1;
z = z + 1;
}
printf ("%d\n", p);
return 0;
}
I get a runtime error each time I try running this code on IDEONE.

No comments:

Post a Comment