“Größte und kleinste in 3 Zahlen CPP” Code-Antworten

Größte und kleinste in 3 Zahlen CPP

// greatest / smallest among three

#include <iostream>
using namespace std;

int main()
{
    int a, b, c, greatest , smallest;

    cout<< "Enter three numbers: ";
    cin>> a >> b >> c;

    if(a>b && a>c)
        greatest = a;

    else if(b>a && b>c)
        greatest = b;

    else
        greatest = c;

    if(a<b && a<c)
        smallest = a;

    else if(b<a && b<c)
        smallest = b;

    else
        smallest = c;

    cout << "Greatest = " << greatest <<endl;
    cout << "smallest = " << smallest;

    return 0;
}
Sleep deprived

Programm zum dritt kleinsten Nummer C.

#include<bits/stdc++.h>
#define MAX 100000
using namespace std;
 
int Print3Smallest(int array[], int n)
{
    int firstmin = MAX, secmin = MAX, thirdmin = MAX;
    for (int i = 0; i < n; i++)
    {
        /* Check if current element is less than
           firstmin, then update first, second and
           third */
        if (array[i] < firstmin)
        {
            thirdmin = secmin;
            secmin = firstmin;
            firstmin = array[i];
        }
 
        /* Check if current element is less than
        secmin then update second and third */
        else if (array[i] < secmin)
        {
            thirdmin = secmin;
            secmin = array[i];
        }
 
        /* Check if current element is less than
        then update third */
        else if (array[i] < thirdmin)
            thirdmin = array[i];
    }
 
    cout << "First min = " << firstmin << "\n";
    cout << "Second min = " << secmin << "\n";
    cout << "Third min = " << thirdmin << "\n";
}
 
// Driver code
int main()
{
    int array[] = {4, 9, 1, 32, 12};
    int n = sizeof(array) / sizeof(array[0]);
    Print3Smallest(array, n);
    return 0;
}
Lonely Lynx

Ähnliche Antworten wie “Größte und kleinste in 3 Zahlen CPP”

Fragen ähnlich wie “Größte und kleinste in 3 Zahlen CPP”

Weitere verwandte Antworten zu “Größte und kleinste in 3 Zahlen CPP” auf C++

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen