How to find greatest of two numbers using if else statement in C Language

Introduction: In previous post i explained How to find greatest of two numbers using conditional operator in C Language and Else if ladder or multiple else if to check character is vowel or consonant in C language. In this post i will explain how you can find greatest of 2 numbers using if else statement in C Language.  Concept is very simple. Just check whether first number is greater than the second number or not. if greater, then first number is the greatest number else second number is the greatest number .Let's create a program.

#include<conio.h>
#include<stdio.h>
main()
{
      int a,b;
      printf("Enter first number: ");
      scanf("%d",&a);
      printf("Enter second number: ");
      scanf("%d",&b);
      if(a>b)
        {
             printf("%d is greatest number",a);
         }
       else
        {
             printf("%d is greatest number",b);
        }
                 getch();
  }
  • Run the program using Ctrl+F9
OUTPUT:
Enter first number: 2
Enter second number: 8
8 is greatest number
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily..