Dremendo Tag Line

Input 10 numbers and print the smallest using while loop in C++

while Loop - Question 3

In this question, we will see how to input 10 numbers and print the smallest among them in C++ programming using while loop. To know more about while loop click on the while loop lesson.

Q3) Write a program in C++ to input 10 numbers and print the smallest among them using while loop.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int i=1,n,sm;

    cout<<"Enter 10 numbers\n";
    while(i<=10)
    {
        cin>>n;
        if(i==1)
        {
            sm=n;		// store the first number
        }
        else if(n<sm)		// compare the previous stored number with the latest entered number
        {
            sm=n;
        }

        i=i+1;
    }
    cout<<"Smallest Number = "<<sm;
    return 0;
}

Output

Enter 10 numbers
12
6
48
95
3
11
27
36
54
89
Smallest Number = 3
video-poster