C program to find greatest of two number


 C program to find greates of two number

Explaination:-

The program given below is to find the greatest of two integers where we have used conditional if-else statement to find the greatest integer between any two number. If the first integer is bigger than the second integer then it will print first number is greater then second otherwise the program will print second number is greater than first number.

Algorithm:-

  1. Start
  2. Input two numbers
  3. Check whether a is greater than b
  4. If yes print a is greater else b is greater
  5. Stop

In this we are implementing the program in two ways fist we directly initialize the values a and b and in the second program we are the input from the user as you can see below. So we implement the program using the if else statements in which first it checks whether the first number is greater than the other and if yes then prints a is greater than b and if the condition evaluates to false then print b is greater than a.

program:-

#include <stdio.h>

int main()
{
    int a=432, b=168;
    printf("****Program to check greatest of two numbers****");
    
    if(a > b){
        printf("%d is greater than %d", a, b);
    }else {
        printf("%d is greater than %d", b, a);
    }

    return 0;
}

output:- 

****Program to check greatest of two numbers****                                                                      
Enter two numbers: 432 168                                                                                            
432 is greater than 168 


program with user input:-


#include <stdio.h>

int main()
{
    int a, b;
    printf("****Program to check greatest of two numbers****");
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    if(a > b){
        printf("%d is greater than %d", a, b);
    }else {
        printf("%d is greater than %d", b, a);
    }

    return 0;
}

output:- 

****Program to check greatest of two numbers****                                                                      
Enter two numbers: 432 168                                                                                            
432 is greater than 168 



****Program to check greatest of two numbers****                                                                      
Enter two numbers: 23 56                                                                                              
56 is greater than 23

Post a Comment

0 Comments