Write a c program that prompts the user to enter 3 integers
Write a c program that prompts the user to enter 3 integers separated by spaces, assigns the integers to an array, and then prints the integers in ascending order. Include a function in your program that takes two integer parameters and returns the largest one. Use that function to help you sort the numbers. Include the algorithm for your program as a multi-line comment at the bottom of your file.
As your written answer to this question, give the output for your program when given the following input:
12 8 2
555 89999 1233456
0 88 -1
5 6 5
Solution
#include<stdio.h>
#include<conio.h>
int sort(int,int);
int main() {
int a,b,c,i,j,temp;
int arr[30];
printf(\"\ Enter 3 numbers seperated by spaces : \");
scanf(\"%d%d%d\", &a,&b,&c);
arr[0]=a;
arr[1]=b;
arr[2]=c;
for (i = 0; i < 3; ++i)
printf(\"%d \", arr[i]);
for (i = 0; i < 3; ++i)
{
for (j = i + 1; j < 3; ++j)
{
temp=sort(arr[i],arr[j]);
if(temp==arr[i]){
arr[i]=arr[j];
arr[j]=temp;}
}
}
printf(\"\ The numbers arranged in ascending order are given below \ \");
for (i = 0; i < 3; ++i)
printf(\"%d \", arr[i]);
getch();
}
int sort(int x,int y){
if(x>y)
return x;
else
return y;
}
output for the given inputs:
2 8 12
555 89999 1233456
-1 0 88
5 5 6

