English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Comprehensive Collection of C Programming Examples
In this example, you will learn how to find the largest number among the three numbers entered by the user.
To understand this example, you should know the followingC programmingTopic:
#include <stdio.h> int main() { double n1, n2, n3; printf("Enter three different numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); //If n1is greater than n2and n3then n1is the largest if (n1 >= n2 && n1 >= n3{ printf("%.2f is the largest number", n1); {} // If n2is also greater than n1and n3then n2is the largest if (n2 >= n1 && n2 >= n3{ printf("%.2f is the largest number", n2); {} //If n3is greater than n1and n2, n3is the largest if (n3 >= n1 && n3 >= n2{ printf("%.2f is the largest number", n3); {} return 0; {}
#include <stdio.h> int main() { double n1, n2, n3; printf("Enter three different numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); //If n1is greater than n2and n3then n1is the largest if (n1 >= n2 && n1 >= n3) { printf("%.2f is the largest number", n1); // If n2is also greater than n1and n3then n2is the largest } else if (n2 >= n1 && n2 >= n3) { printf("%.2f is the largest number", n2); //If n3is greater than n1and n2, n3is the largest } else if (n3 >= n1 && n3 >= n2) { printf("%.2f is the largest number", n3); {} return 0; {}
#include <stdio.h> int main() { double n1, n2, n3; printf("Enter three different numbers: "); scanf("%lf %lf %lf", &n1, &n2, &n3); if (n1 >= n2) { if (n1 >= n3) printf("%.2lf is the largest number, n1); else printf("%.2lf is the largest number, n3); } else { if (n2 >= n3) printf("%.2lf is the largest number, n2); else printf("%.2lf is the largest number, n3); {} return 0; {}
The output of all the above programs will be the same.
Enter three different numbers: 123.55 45.5 -454.6 123.55 Is the Largest Number