Computer Science Of Engineering

Simple and practical computer science tutorials, programming guides, and engineering concepts for students and beginners.

Breaking

Friday, April 18, 2025

Find the maximum of three numbers using conditional operator in C

  Find the maximum of three numbers using conditional operator in C


Program:


#include <stdio.h>


int main() {

    int a, b, c, max;


    // Input three numbers

    printf("Enter three numbers: ");

    scanf("%d %d %d", &a, &b, &c);


    // Using conditional (ternary) operator

    max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);


    // Output result

    printf("Maximum number is: %d\n", max);


    return 0;

}

Output:


No comments:

Post a Comment