Write a program which declares an array of integers of size maximum size 20, asks the user to enter its effective size (should be less than 20) and allows the user to fill his values. This program should not accept values greater than 150. In other words, if the user fills a value greater than 150, the program does not insert the value in the array and asks again for a new value of the user.


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <math.h>
int main()
{
    int A[20];
    int N;
    int I;      
    
    do{
        printf("Enter N: ");
        scanf("%d",&N);
    }while(N<0 || N>20);

    for (I=0 ; I<N ; I++)
    {
        do{
            printf("Enter element %d : ", I+1);
            scanf("%d", &A[I]);
        }while(A[I]>150);
    }
 
    for (I=0 ; I<N ; I++)
            printf("%d ", A[I]);
    printf("\n");
    
    return 0;
} 

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Using the double hashtag operator in macro expansion