Write a C Program to Find the Second Largest Number among Three Variables

July 12, 2022 0 Comments

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.


write c program to find second largest number among three variables




Write a Program to Find the Second Largest Number among Three Variables

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;
}



Test Live At Jdoodle



Conclusion

This is how you can find the second largest number among three variables in c programming. Comment below if you like our tutorial.

Leave a comment

Gallery