In this tutorial learn how you can write a c program to find the second largest number among three variables.
We are using if, else, and else if conditions for this tutorial.
C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.
Here is the code to find the second largest number among three variables in C programming.
#include <stdio.h> //WAP to find the second largest number among three variables.
int main(){
int a,b,c;
printf("Please enter three numbers:n");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c){
if(b>c){
printf("%d is second largest number.",b);
}
else { printf("%d is second largest number.",c); }
}
else if (b>a&&b>c)
{
if(a>c){
printf("%d is second largest number.",a);
}
else {printf("%d is second largest number.",c);
}
}
else if (c>a&&c>b){
if(a>b){
printf("%d is second largest number.",a);
}
else printf("%d is second largest number.",b);
}
return 0;
}
This is how you can find the second largest number among three variables in c programming. Comment below if you like our tutorial.