Program 7 - CSU1128 - CSE 2026 - Shoolini University

Program to check maximum between three numbers.

Explanation

The following code is a simple program that checks the maximum value between three numbers entered by the user.

#include <stdio.h>

The above line is an include statement that includes the standard input/output library in the program. This library provides functions such as scanf and printf.

int main()
{
                

The main function is the starting point of the program where all the logic is defined.

int d, m, j, o, n;
printf("\n\n Program to check maximum between three numbers. \n\n");
printf("Enter three numbers with a space - (Example: 23 54 76) - and press enter: ");
scanf("%d %d %d", &d, &m, &j);
printf("\n Maximum between the entered number is ");

The above code declares 5 integer variables d, m, jj, o and n. The printf statement is used to display a prompt asking the user to enter three numbers separated by a space. The scanf statement is used to read these three numbers entered by the user and store them in variables d, m, and j. The next printf statement displays a message indicating that the maximum between the entered numbers will be displayed.

o = d > m ? d : m;
n = o > j ? o : j;
printf(" %d.\n", n);
                

The above code uses the ternary operator to find the maximum value between three numbers. The expression d > m returns true if d is greater than m and false otherwise. If it is true, then d is assigned to o. If false, then m is assigned to o. The next line uses the same logic to find the maximum between o and j and assigns it to n. Finally, the maximum value is displayed using the printf statement.

return 0;
}

The return statement with a value of 0 indicates that the program has executed successfully.

Code

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128)
 * Instructor: Dr. Pankaj Vaidya | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>
int main()
{
    int d, m, j, o, n;
    printf("\n\n Program to check maximum between three numbers. \n\n");
    printf("Enter three numbers with a space - (Example: 23 54 76) - and press enter: ");
    scanf("%d %d %d", &d, &m, &j);
    printf("\n Maximum between the entered number is ");

    o = d > m ? d : m;
    n = o > j ? o : j;
    printf(" %d.\n", n);
    return 0;
}

Output

Program to check maximum between three numbers

Enter three numbers with a space - (Example: 23 54 76) - and press enter: 32 77 43
 Maximum between the entered number is 77.