Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS151 / KCS251 Programming for Problem Solving - Using C Language


Lab Exercises


4. Write a program to find the largest of three numbers using nested if-else.


/*
 File: Prgrm04.c
 Author: Aditya Saini
 Date: Jan 16, 2021
 Description: Program to find the largest of three numbers using nested if-else.
*/

#include <stdio.h>

int main (void)
{
     int num_1, num_2, num_3;
     int greatest;

     //Input numbers
     printf ("Input first number: ");
     scanf ("%d", &num_1);
     printf ("Input second number: ");
     scanf ("%d", &num_2);
     printf ("Input third number: ");
     scanf ("%d", &num_3);

     //Finding the greatest number
     if (num_1 >= num_2 && num_1 >= num_3)
          greatest = num_1;
     else if (num_2 > num_3)
          greatest = num_2;
     else
          greatest = num_3;

     //Print result
     printf ("Greatest number: %d", greatest);

     return 0;
};

Output

Input first number: 4
Input second number: 5
Input third number: 6
Greatest number: 6



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib