main()
{
    int s=0;
    while(a && b && c)
    {
        s++;
        a--;
        b--;
        c--;
    }
    printf("%d",s);
}

i know that here a,b,c are undeclared, but beside that i can't find the problem.
so anyone can help me out here.
thanks

Dani AI

Generated

The snippet in the first post will both fail to compile and — even if fixed — has logic problems. As noted, headers and variable declarations are required; as added, the decrement-loop only behaves as intended when all three inputs are positive and non-zero. That loop is O(min(a,b,c)) and gives wrong results for negative values (example: a = -1, b = 3, c = 5 yields s = 3, not -1), so it is fragile and slow for large numbers.

A simple, correct and efficient solution is to read the three ints and use comparisons to pick the minimum:

#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int a, b, c;
    if (scanf("%d %d %d", &a, &b, &c) != 3) return 1;
    int min = a;
    if (b < min) min = b;
    if (c < min) min = c;
    printf("%d\n", min);
    return 0;
}

If the goal is specifically to avoid comparison operators, a portable arithmetic trick uses absolute differences: min(a,b) = (a + b - abs(a - b)) / 2, then apply it again with the third value. That avoids explicit </> but requires care for overflow; use a wider type (long long) and llabs if inputs can be large.

Additional notes: always initialize variables and check scanf return, prefer int main(void) with return 0, and avoid the decrement-loop for production code because of correctness and performance issues.

Recommended Answers

All 2 Replies

Member Avatar for Member #1042208

Two Problems:
1) You haven't provided header files. Atleast stdio.h
2) You haven't declared variables.

Otherwise worked fine for me.
2777039855db14d41749c869148bc73d

Not only do a, b, and c need to be declared, they also (in Rahul47's example) need to be initialized to non-zero values. So, in your case, that IS the problem! :-)

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.