C Program to Find the Greatest of the Two Numbers

Find the Greatest of the two numbers in C

Given two integer inputs num1 and num2, the objective if to write a code to Find the Greatest of the     

Two Numbers in C.

Example

Input : num1 = 5 and num2 = 6

Output : 6

Flow Diagram:-

Greatest of two numbers.png

Code:-

  • If num1 == num2

  •        Print both are equal

  • Else if num1 > num2

  •       Print num1 is greater

  • Else, num2 has to be the greater

  •       Print num2 is greater

Algorithm:-

Code:-

#include<stdio.h>

int main ()
{
  int num1, num2;
 
  printf ("Enter two numbers: ");
  scanf ("%d %d", &num1, &num2);
 
  if (num1 == num2)
      printf("both are equal");
  else if (num1 > num2)
      printf("%d is greater", num1);
  else
      printf("%d is greater", num2);

  return 0;
}

Output:-

Enter a number: 22 10

22 is greater