Search
 
SCRIPT & CODE EXAMPLE
 

CPP

greatest and smallest in 3 numbers 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;
}
Comment

program to find third smallest number 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 << "
";
    cout << "Second min = " << secmin << "
";
    cout << "Third min = " << thirdmin << "
";
}
 
// Driver code
int main()
{
    int array[] = {4, 9, 1, 32, 12};
    int n = sizeof(array) / sizeof(array[0]);
    Print3Smallest(array, n);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cpp queue 
Cpp :: transform cpp 
Cpp :: cpp tutorial 
Cpp :: c++ for loops 
Cpp :: void pointer c++ 
Cpp :: std::string remove last 
Cpp :: how to make an enum in c++ 
Cpp :: insert into a vector more than once c++ 
Cpp :: string array 2d c++ 
Cpp :: c++ influenced 
Cpp :: friend class c++ 
C :: C bold output 
C :: how to store a user input with spaces in c 
C :: c remove last character from a string 
C :: sstf program in c 
C :: react-textfit 
C :: line counter in c 
C :: binary search in c 
C :: Successeur récurssive 
C :: get current used proxy windows 7 
C :: count number of vowels in a string in c 
C :: c program to add two numbers 
C :: right side of div 
C :: read string with space c 
C :: print short in c 
C :: c sleep milliseconds 
C :: c read file 
C :: round float in c 
C :: printing out an array in c from user input 
C :: number pattern in c 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =