write a program to input 3 numbers and print them in ascending order
Priyanka2003:
In what java,c++,QBasic,python?
Answers
Answered by
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!!
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!!
Answered by
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!
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
Chemistry,
8 months ago
English,
8 months ago
Social Sciences,
8 months ago
Physics,
1 year ago
English,
1 year ago