Member Avatar for Member #450068

Write program in C that would read 3 figures from the 1 up to the 999 and him it presents all in a line from smallest in biggest.

Dani AI

Generated

As , and suggested, it helps to see a working example. Below is a compact, robust C program that reads three integers (each must be 1..999), validates the input, and prints them on one line from smallest to largest. It uses only simple comparisons and swaps — minimal and easy to understand for three values.

#include <stdio.h>

int main(void) {
    int a, b, c, tmp;
    printf("Enter three integers (1-999): ");
    if (scanf("%d %d %d", &a, &b, &c) != 3) {
        fprintf(stderr, "Invalid input: expected three integers\n");
        return 1;
    }
    if (a < 1 || a > 999 || b < 1 || b > 999 || c < 1 || c > 999) {
        fprintf(stderr, "Each number must be between 1 and 999\n");
        return 1;
    }
    if (a > b) { tmp = a; a = b; b = tmp; }
    if (a > c) { tmp = a; a = c; c = tmp; }
    if (b > c) { tmp = b; b = c; c = tmp; }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Notes: the three pairwise swaps guarantee a <= b <= c after execution. Check scanf's return value to catch non-numeric input; validate ranges explicitly since the problem requires 1..999. If a more general solution is wanted (n numbers), use an array plus qsort or a simple sort routine. If this program doesn't behave as expected for specific inputs, post the exact input and compiler errors — that will make troubleshooting easier, as and recommended.

Recommended Answers

All 5 Replies

You must post your code and ask for solving. ;)

Show us what you've got and we'll help you in solving any problems you have.

Show your work first..! and we will help you!

How many people have to post the exact same message? Isn't one enough? :icon_rolleyes:

How many people have to post the exact same message? Isn't one enough? :icon_rolleyes:

Me and VatooVatoo posted the message simultaneously. I would've deleted my post, but since that isn't an option i just left it.

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.