Hye all!! here is an program statement i don't know how to do it :o ..so plz let me know itz solution...
program is written below:-
Write a program that will get 10 numbers between 20 and 100 and store them in one dimensional array of type int , as each number is entered by the user from keyboard. Your program will check that if number is between the range of 20 and 100. Now there are two cases:

1. The number is already entered by the user then it will not be stored in array and your program will continue to get next number from the user.


2. The entered number is unique and was not previously entered by the user now your program will store that number in the array and continue to get next number from the user.

At the end your program will simply display the non duplicate values entered by the user.

Sample output:

Out put of your program will be as followed:


Enter 10 values between 20 and 100
Enter Value
50
Enter Value
60
Enter Value
70
Enter Value
56
Enter Value
89
Enter Value
200
your value should be between 20 and 100
Enter Value
47
Enter Value
50
Enter Value
5
your value should be between 20 and 100
Enter Value
56
Enter Value
95
Enter Value
21
The non duplicate values are: 50 60 70 56 89 47 95 21

Dani AI

Generated

The sample thread shows two small but important gaps: the exercise expects ten valid (in‑range) entries to be read from the keyboard, but only unique values among those ten are stored; and simple range checks (as sketched) need proper input handling so non‑numeric input or buffer leftovers don't break the loop. A clear pattern is: keep a counter of how many in‑range entries have been entered (stop when it reaches 10), and separately keep an array of stored unique values that grows only when a new value is not already present.

The following compact C example implements that pattern, handles non‑numeric input safely, rejects out‑of‑range values without counting them toward the ten, and ignores duplicates while still counting them as valid attempts:

#include <stdio.h>

int main(void) {
    const int REQUIRED = 10;
    int stored[REQUIRED];
    int storedCount = 0;
    int inRangeCount = 0;
    int n;

    while (inRangeCount < REQUIRED) {
        printf("Enter Value\n");
        if (scanf("%d", &n) != 1) {
            printf("Invalid input; enter an integer.\n");
            int ch;
            while ((ch = getchar()) != '\n' && ch != EOF); /* clear input */
            continue;
        }
        if (n < 20 || n > 100) {
            printf("your value should be between 20 and 100\n");
            continue;
        }
        inRangeCount++; /* count this as one of the 10 inputs */
        int found = 0;
        for (int i = 0; i < storedCount; ++i)
            if (stored[i] == n) { found = 1; break; }
        if (!found) stored[storedCount++] = n;
    }

    printf("The non duplicate values are: ");
    for (int i = 0; i < storedCount; ++i) printf("%d ", stored[i]);
    printf("\n");
    return 0;
}

A few practical notes: 's exit() suggestion ends the program and doesn't help re‑prompting; prefer printing a message and continuing. Avoid fflush(stdin) (undefined behavior)—use a getchar() loop to clear leftovers after scanf failures. For larger ranges or faster duplicate checks, a boolean "seen" table indexed by value can replace the linear search.

Recommended Answers

All 7 Replies

I notice a lack of attempt on your part. It seems like you're asking us to do your work for you.

It doesn't work that way around here. Sorry.

actually i need to know how to check that the numbers entered by the user are b/w the range of 20 and 200..how can we check it in array...

for ( i = 0; i < size; i++ ) {
  if ( array[i] < 20 || array[i] > 100 )
    error();
}

can u plz explain error();

>can u plz explain error();
I would think it was obvious. It's a placeholder meaning "error code goes here".

If you preffer you can use

exit()

instead of error()

That's not any help. As pseudocode, it's no better than error(), and in real code, exit requires an argument. So either way, you've gained nothing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.