22/02/2019

Find the largest number in C-Programming

Find the largest number in C-Programming:

 Here we find the largest number among 3 three numbers. We first give the required code then we will explain. This programming is valid for real numbers not for complex numbers.
Find the largest number in C-Programming

Important Tools:

1. if-else

Code:

Find the largest number in C-Programming


#include<stdio.h>
int main()
{
  float a,b,c;
  printf("Enter the three numbers:");
  scanf("%f%f%f",&a,&b,&c);
  if(a>b && a>c)
  printf("%f is the largest number among %f,%f,%f",a,a,b,c);
  if(b>a && b>c)
  printf("%f is the largest number among %f,%f,%f",b,a,b,c);
  else
  printf("%f is the largest number among %f,%f,%f",c,a,b,c);
}

Output:

The output is given below:
Find the largest number in C-Programming

Explanation:

1. First of all we used header package <stdio.h>.
2. We use 3 float variables a,b,c for store the three numbers which are given by the users.
3. We use if-else here. First if is used for if a is the largest and the second if is used for if b is largest and for c we use the else case. For know more about the use of if-else command, please visit our syntax page.
4. Point that i don't use any curly bracket after the command if and else. Since only one statement are there after if command and also after else command so it not necessary to use this curly bracket. You can use it if you want there is no problem.

                                       If you have any doubts comment below.

No comments:

Post a Comment