I have a problem with my code. It should take from user amount of numbers in array and user should write the number he wants in range 1-100.
Also the program should display the smallest and the highest number. If I want to have an array with more than 7 numbers, it crashes down while I type in the numbers.
Every time when it comes to the number 7, program crashes. I have no idea why it isn't working.
#include <stdio.h>
#include <stdlib.h>
int n, i, a;
int main ()
{
int tab[n];
printf("\nhow many elements you want to have?\n");
do
{
scanf ("%d", &n);
if ((n>30 || n<1))
printf("\ntoo high or too low\n");
}
while ((n<1 || n>30));
printf("\nyour number please:\n");
for(i = 0; i < n; i++)
{
do
{
printf("\nelement %d:", i+1);
scanf("%d", &a);
if ((a < 1 || a > 100))
printf("\nnumber too high or too low\n");
tab[i]=a;
}
while((a < 1 || a > 100));
}
printf("\nyour numbers:");
for (i=0; i<n; i++)
{
printf("\n%d", tab[i]);
}
int min = tab[0];
int max = tab[0];
for (i = 0; i<n; i++)
{
if (tab[i]> max)
max = tab[i];
if(tab[i]< min)
min = tab[i];
}
printf("\nsmallest: %d", min);
printf("\nbiggest: %d", max);
}