Welcome!!

Today in this blog we are going to learn how to write a program to find the largest number among three numbers in C. In order to understand this blog, I prefer you to take a look on loops in C, so you can understand better.

Knowledge Chatter

Concept: -

First we are going to take input from user (scanf). That is three numbers. For that we use the syntax:-

  • scanf("%d\n%d\n%d", &a,&b,&c);

And then for loop is used for conditions. Syntax for for loop is :-

  • If ( condition ) {….Codes……}

Note:- We can use as many if loops in ‘if loop’ there won’t be any error.

And one more thing you need to know that is ‘&&’ operator this operator is known as AND operator it signifies that – if both of the condition that is written is right then the given code inside the if loop will be executed.

Now, the question is that what should we write in the conditions. Here in this question we are going to write three conditions : -

1 – If a is greater than and equal to b and c then a is largest.

2 – If b is greater than and equal to a and c then b is largest.

3 – If c is greater than and equal to a and b then c is largest.

Now, time to apply these concepts to solve given the question.

Solution: -

Knowledge Chatter


#include<stdio.h>

int main(){

               int a, b, c;

              

               printf("Enter the number a, b and c\n");

               scanf("%d\n %d\n %d", &a,&b,&c);

              

               if (a>=b && a>=c){

                              printf("Largest number is %d", a);

               }

               if (b>=a && b>=c){

                              printf("Largest number is %d", b);

               }

               if (c>=a && c>=b){

                   printf("Largest number is %d", a);

               }

               return 0;

}

Above I have provided image and textual form of the solution. I hope that you won’t just copy paste try to understand the code.

Well, that’s it here is the solution and if you have any difficulty in understanding any line of the code, feel free to ask me in the comment section. ðŸ˜ƒ

And if there is any mistake feel free to correct me and do let me know in the comment section.

You can also visit the following link ðŸ‘‡

Hello world in C - HackerRank Solution

Sum and Difference of two no. in C - HackerRank Solution

Input and Output in C++ - HackerRank Solution