Write a C, C++ program to find the greatest number among three numbers.

In this program take three input numbers from user and find greatest number among three. You can solve this problem using multiple approaches.

C, C++ Practice Questions

## C++ Program to Find Greatest Number among three

#include <iostream> using namespace std; int main() { int a,b,c; cout<<"Enter three numbers"; cin>>a>>b>>c; /*check whether a is greater than b and c*/ if(a>b && a>c) { cout<<"Greatest number is"<<a; /* check whether b is greater than a and c */ }else if(b>a && b>c) { cout<<"Greatest number is"<<b; } else { cout<<"Greatest number is"<<c; } return 0; }

## C Program to Find Greatest Number among three

#include <stdio.h> int main(){ int a, b, c; printf("Enter three numbers "); scanf("%d %d %d", &a, &b, &c); if (a > b && a > c) { printf("%d is Greatest",a); } else if (b > a && b > c) { printf("%d is Greatest",b); } else { printf("%d is Greatest",c); } return 0; }

**Output :**

**Enter three numbers : 8 2 1**

8 is Greatest

## No comments:

## Post a Comment