0
#include <bits-stdc++.h>

void main()
{
    int i = 0, LARGEST = 0, SMALLEST = 0, COUNT = 1, n;

    do {
        printf(" \n\n Enter the number %d :-  ", COUNT);
        std::cin >> i;
        COUNT++;
        if (i > LARGEST) {
            LARGEST = i;
        }
        else if (i == 99) {
            printf("\n\ncheck out ..... ");
            break;
        }
        n = i;

    } while (i != 99);

    std::cout << "\n the greatest num is  = " << LARGEST;
}

How to make this program give me the smallest number , its already gives me the greatest one , what should I do to make it print the smallest num ??

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Kobrakixx
  • 13
  • 5
  • 1
    surely exactly the same code as you've got for `LARGEST` will work? You just need to initialise `SMALLEST` with a suitably large number (e.g. [`std::numeric_limits::max`](https://en.cppreference.com/w/cpp/types/numeric_limits/max)) – Alan Birtles Oct 02 '22 at 18:57
  • 1. If negative inputs are allowed, your greatest functionality won't work. 2. smallest is done in the same conceptual manner as greatest, so once firmly grasp how the approach for greatest works, you will also know how to do smallest. – Avi Berger Oct 02 '22 at 19:00
  • printf or std::cout, one must choose. In C++ rather std::cout. – CGi03 Oct 02 '22 at 19:06
  • Guys I tried what you all said and it worked ,,, THANKS !! – Kobrakixx Oct 02 '22 at 19:10
  • Also note [Why including bits/stdc++.h is bad practice](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – oraqlle Oct 03 '22 at 01:35

0 Answers0