StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #6 (U1): Maximum of Two Numbers (if/else)
Download
  1. C Programming
  2. C Programming Practice
Program #5 (U1): Temperature Converter (°C ↔ °F) : Program #7 (U1): Even/Odd Checker
C Programming Practice

Task: Read two integers and print the larger one using a simple if/else. If both numbers are equal, print an explicit message.

 
/* 

  Program: Maximum of Two Numbers (U1)

  What it does:

    - Reads two integers x and y from the user.

    - Compares them using if/else and prints the larger value.

    - If both are equal, prints a special message indicating equality.

*/

 
#include <stdio.h>

 
int main(void) {

    int x, y;

 
    printf("Enter two integers (x y): ");

    if (scanf("%d %d", &x, &y) != 2) {

        printf("Invalid input. Please enter two integers.\n");

        return 0;

    }

 
    /* Compare and print result */

    if (x > y) {

        printf("Maximum = %d (x is greater than y)\n", x);

    } else if (y > x) {

        printf("Maximum = %d (y is greater than x)\n", y);

    } else {

        printf("Both numbers are equal: %d\n", x);

    }

 
    /* Example:

       Input: x=10 y=3  -> Maximum = 10 (x is greater than y)

       Input: x=7  y=9  -> Maximum = 9 (y is greater than x)

       Input: x=5  y=5  -> Both numbers are equal: 5

    */

 
    return 0;

}

 

 

Program #5 (U1): Temperature Converter (°C ↔ °F) Program #7 (U1): Even/Odd Checker
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website