Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Is there any ways for me to code this program in an easiest way without using array?

0 votes
asked Jan 17, 2019 by Simon Barrenuevo (120 points)
#include <iostream>

using namespace std;

int main()
{
    int a = 4, b = 4, c = 5;
    
    //arranging 3 integers in ascending order
    
    if (a < b && b < c){
        cout << a << " " << b << " " << c;
    }else if (a < c && c < b){
        cout << a << " " << c << " " << b;
    }else if (b < c && c < a){
        cout << b << " " << c << " " << a;
    }else if (b < a && a < c){
        cout << b << " " << a << " " << c;
    }else if (c < a && a < b){
        cout << c << " " << a << " " << b;
    }else if (c < b && b < a){
        cout << c << " " << b << " " << a;
    }else if (a == b && b < c){
        cout << a << " " << b << " " << c;
    }else if (b == c && c < a){
        cout << c << " " << b << " " << a;
    }else{
        cout << "They are equal";
    }

    return 0;
}

4 Answers

0 votes
answered Jan 23, 2019 by anonymous
#include<iostream>

using namespace std;

int main()

{

long int a,b,c;

cout<<enter a,b&c values;

cin>>a>>b>>c;

if(a<b&&a<c)

cout<<a;

else if(b<c)

cout<<b;

else

cout<<c;

}
commented Jan 24, 2019 by anonymous
I think it gives least value. It doesn't arranges them in sorting order.
commented Jan 24, 2019 by MithunKumar (140 points)
#include<iostream>

using namespace std;

int main()

{

long int a,b,c;

cout<<a,b&c;

cin>>a>>b>>c;

if(a<b&&a<c)

cout<<a;

else if(b<c)

cout<<b;

else

cout<<c;
}
output is
4196310
0 votes
answered Jan 24, 2019 by anonymous
#include<stdio.h>
void swapa(int *x,int *y)
{
    *x=*x+*y;
    *y=*x-*y;
    *x=*x-*y;
}
main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
   if(a>b)
      swapa(&a,&b);
    if(a>c)
      swapa(&a,&c);
    if(b>c)
      swapa(&b,&c);
      printf("%d %d %d",a,b,c);

}
0 votes
answered Jan 24, 2019 by MithunKumar (140 points)
4 4 5

this is a final output
commented Jan 24, 2019 by anonymous
I just assume that what if the input numbers have the same value...like 4, 4, 5..
0 votes
answered Jan 25, 2019 by anonymous
//if this one seems simpler ??? 8-)
int main()
{   int a = 3, b = 4, c = 5;
    int swap;

    if ( b < a )
    {   swap = b;
        b = a;
        a = swap;
    }
    if ( c < a )    // c goes before a
    {  swap = c;
       c = b; 
       b = a;
       a = swap;
    } else          // c mid a,b
    {  swap = c;
       c = b;
       b = swap;
    } 
    cout << a << " " << b << " " << c;
}       
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...