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 :: find nth fibonacci number 
Cpp :: DS1302 
Cpp :: c++ - 
Cpp :: unordered_map c++ 
Cpp :: find first of a grammar 
Cpp :: c++ map 
Cpp :: c++ memory address 
Cpp :: compare function in c++ 
Cpp :: c++ program to find gcd of 3 numbers 
Cpp :: c++ string concatenation 
Cpp :: find maximum sum of circular subarray 
Cpp :: stack data structure c++ 
Cpp :: Shell-Sort C++ 
Cpp :: flutter text direction auto 
Cpp :: C++ Class Template Declaration 
Cpp :: Write a C++ program using constructor 
Cpp :: inverted triangle c++ 
Cpp :: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope 
Cpp :: print numbers after decimal point c++ 
Cpp :: short int range in c++ 
Cpp :: top array data structure questions in inteviews 
Cpp :: find no of occurences of each letter in string c++ 
Cpp :: qtextedit no line break 
Cpp :: how to signify esc key in cpp 
Cpp :: Types of Triangles Based on Angles in c++ 
Cpp :: how to change the icon of an exe in c++ 
Cpp :: https://stackoverflow.comInstance of a Character in a String c++ 
Cpp :: number of characters in string 
Cpp :: go to particular place in vector using iterator 
Cpp :: command loop ctrl D c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =