brel-logo-white brel-logo-white
  • Travel
  • Case Study
  • How to
  • Technology
  • More
    • Sports
    • Health
    • Articles
    • Review
Notification
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
BreldigitalBreldigital
  • HomeHome
  • Finance
  • Health
  • Lifestyle
  • Sports
  • Contact Us
Search
  • Quick Access
    • Home
    • History
    • My Saves
    • My Interests
    • My Feed
  • Categories
    • Travel
    • Sports
    • Health

Top Stories

Explore the latest updated news!

What idea is emphasized through repetition

The a value of a function in the form f(x) = ax2 + bx + c is negative. which statement must be true?

What experimental evidence led to the development of this atomic model from the one before it?

Stay Connected

Find us on socials
248.1k Followers Like
61.1k Followers Follow
165k Subscribers Subscribe
Breldigital > Blog > ds > Write a program that takes three numbers as input and prints the largest.
ds

Write a program that takes three numbers as input and prints the largest.

By John Published November 10, 2022
Share

In C programming, the largest element of a number is the number with the highest numerical value of the three numbers.

For example, if three numbers are given, 1, 2, 3, the largest of the three numbers is 3.

Problem Description
Write a C program that takes the 3 numbers and finds the largest number Aamong three numbers.

Problem Solution
Alorithm:
1. Take the three numbers as input and store them in variables.
2. Check the first number if it is greater than other two.
3. Repeat the step 2 for other two numbers.
4. Print the number which is greater among all and exit.

There are several ways to find the largest number among three numbers in C language. Let’s take a detailed look at all the approaches to find the largest/biggest of 3 numbers.

Method 1: (Using If Statement)
In this approach, we will calculate the largest of three numbers using if statement.

Example:
Input:
Enter three numbers:
a = 6; b = 8; c = 10

Step 1: Check if (a > b && a > c) i.e if(6 > 8 && 6 > 10). Since 6 is not greater than 8 and 10, so go to the next condition.
Step 2: Check if (b > a && b > c) i.e if(8 > 6 && 8 > 10). Here 8 is greater than 6, but 8 > 10 does not satisfy the condition, so we move on to the next condition.
Step 3: Check if (c > a && c > b) i.e if(10 > 6 && 10 > b). Since 10 is greater than 6 and 8, so the largest number is 10.

Output:
Biggest number is 10
/*
* C program to find the largest of three numbers
*/

#include

int main()
{
int a, b, c;
printf(“Enter three numbers: \na: “);
scanf(“%d”, &a);
printf(“b: “);
scanf(“%d”, &b);
printf(“c: “);
scanf(“%d”, &c);
if (a > b && a > c)
printf(“Biggest number is %d”, a);
if (b > a && b > c)
printf(“Biggest number is %d”, b);
if (c > a && c > b)
printf(“Biggest number is %d”, c);
return 0;

Runtime Test Cases
Testcase 1: In this case, we enter the values ​​”6, 8 and 10” as input to find the largest of the three given numbers.

Enter three numbers:
a: 6
b: 8
c: 10
Biggest number is 10
Testcase 2: In this case, we enter the values ​​”10, 99 and 87” as input to find the largest of the three given numbers.

Enter three numbers:
a: 10
b: 99
c: 87
Biggest number is 99

TAGGED: Write a program that takes three numbers as input and prints the largest.
John November 10, 2022 November 10, 2022

Search

brel-logo-white brel-logo-white
Explore a wide range of brands and categories with our comprehensive coverage, and stay up-to-date with the latest news and trends by subscribing to our updates.
Categories:
  • Entertainment
  • Travel
  • Sport
  • Contact Us

Quick Links

  • My Feed
  • My Interests
  • History
  • My Saves

About US

  • Adverts
  • Our Jobs
  • Term of Use

© 2023 Brel Digital All Rights Reserved. All logos and images used on this website are registered trademarks of their respective companies

Welcome Back!

Sign in to your account

Lost your password?