Answer to Question #319655 in C++ for Sami

Question #319655

Write a C program which will take 30 numbers from the keyboard and display the min of these numbers . By using

•for loop

•while loop

•do while loop


1
Expert's answer
2022-03-29T11:41:11-0400
#include <iostream>


using namespace std;


int main()
{
    const int n = 30;
    int a[n];
    cout << "Enter array: ";
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }


    int min = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] < min)
        {
            min = a[i];
        }
    }
    cout << "The min of these numbers by using for loop: " << min << "\n";


    int i = 1;
    min = a[0];
    while (i < n)
    {
        if (a[i] < min)
        {
            min = a[i];
        }
        i++;
    }
    cout << "The min of these numbers by using while loop: " << min << "\n";


    i = 1;
    min = a[0];
    do
    {
        if (a[i] < min)
        {
            min = a[i];
        }
        i++;
    } while (i < n);
    cout << "The min of these numbers by using while loop: " << min << "\n";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog