Computer Science, asked by sinhasobhit333, 1 year ago

write a program to input 3 numbers and print them in ascending order


Priyanka2003: In what java,c++,QBasic,python?
sinhasobhit333: yes I'm java c++
Priyanka2003: okay u want this on what language
sinhasobhit333: c++

Answers

Answered by Incredible29
5
Hey
Here's your answer!!

a program to input 3 numbers and print them in ascending order.

Answer:

public class Numbers
{
public static void main (int a, int b, int c)
{
int G = Math.max (a, Math. max (b,c))
int S = Math. min ( a , Math. max (b,c))
int M = ( a + b + c) - ( G + S ) ;
System.out.println( " The no. in ascending order are :");
System.out.println( S ) ;
System.out.println( M) ;
System.out.println( G);
}
}

sample input : 25 , 46, 15
Sample output :
The no. in ascending order are :
15
25
46.

Hope it helps!!

Atulkrishnan: why??
Incredible29: cuz if i post a question u will get notification
Incredible29: so more followers , faster the help arrives :)
Atulkrishnan: But in which programming language u post questions??
Atulkrishnan: I don't know JS and Java.....so plz don't ask about that
Incredible29: java...
Atulkrishnan: But yeah I can give you algorithm for programs
Incredible29: okk....so will u follow??
sinhasobhit333: pls write this progg without using math function
Incredible29: okk....but post the question again
Answered by siddhartharao77
3
#include <iostream.h>
int main()
{
int ar[3];
 int a,b,c;
int d;
cout<<"Enter the numbers: ";
cin>>a;

for(b=0;b<a;b++)
{
 cout<<"Enter element ["<<b+1<<"] ";
 cin>>ar[b];
}
for(b=0;b<a;b++)
 {
 for(c=b+1;c<a;c++)
  {
  if(ar[b]>ar[c])
  {
   d=ar[b];
   ar[b]=ar[c];
   ar[c]=d;
   }
 }
}
cout<<"Ascending order elements:"<<endl;
 for(b=0;b<a;b++)
 cout<<ar[b]<<"\t";
cout<<endl;
return 0;
}

Hope this helps!
Similar questions