write a program to input 3 numbers and display the second largest number
Answers
Answered by
1
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[3], i, j, k;
clrscr();
for(i=0 ; i<3 ; i++)
{
printf(" Enter Number %d : ", i+1 );
scanf("%d" , &arr[i] );
}
for(i=0 ; i<3 ; i++)
{
for(j=i ; j<3 ; j++)
{
if(arr[i] < arr[j])
{
k = arr[j] ;
arr[j] = arr[i] ;
arr[i] = k ;
}
}
}
printf("\n");
printf(" Second Largest Number : %d" , arr[1] );
return 0;
}
Hope this helps!
#include<conio.h>
int main()
{
int arr[3], i, j, k;
clrscr();
for(i=0 ; i<3 ; i++)
{
printf(" Enter Number %d : ", i+1 );
scanf("%d" , &arr[i] );
}
for(i=0 ; i<3 ; i++)
{
for(j=i ; j<3 ; j++)
{
if(arr[i] < arr[j])
{
k = arr[j] ;
arr[j] = arr[i] ;
arr[i] = k ;
}
}
}
printf("\n");
printf(" Second Largest Number : %d" , arr[1] );
return 0;
}
Hope this helps!
Similar questions