Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
7. Write a program to find the greatest of the three numbers.
/*
File: Prgrm07.c
Author: Aditya Saini
Date: Sept 18, 2019
Description: Program to find the greatest of the three numbers.
*/
#include <stdio.h>
int main (void)
{
int number_1, number_2, number_3;
//Input numbers.
printf ("Input first number: ");
scanf ("%d", &number_1);
printf ("Input second number: ");
scanf ("%d", &number_2);
//Input numbers.
printf ("Input first number: ");
scanf ("%d", &number_1);
printf ("Input second number: ");
scanf ("%d", &number_2);
printf ("Input third number: ");
scanf ("%d", &number_3);
scanf ("%d", &number_3);
//Finding the greatest number and output the result.
if (number_1 > number_2 && number_1 > number_3)
{
printf ("First number is greatest.");
}
else if (number_2 > number_3)
{
printf ("Second number is greatest.");
}
else
{
printf ("Third number is greatest.");
}
{
printf ("First number is greatest.");
}
else if (number_2 > number_3)
{
printf ("Second number is greatest.");
}
else
{
printf ("Third number is greatest.");
}
};
Output
Input first number: 25
Input second number: 19
Input third number: 34
Third number is greatest.Input third number: 34
No comments:
Post a Comment
Please do not post spam links.