Skip to content
Question Bank (3 marks) · Q9

Q.Write a C program to compare two values.

Karnataka PUCTextbookLong· 3mImportance★★★★★est
31% · 47/154 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

[!TLDR]

Read two values and use an if...else if...else ladder with the > and < operators to report their relationship.

Comparing two values means deciding whether the first is greater than, less than, or equal to the second. This is done with the relational operators > and < in an if...else if...else ladder.

#include <stdio.h>
int main()
{
    int a, b;
    printf("Enter two values: ");
    scanf("%d %d", &a, &b);
    if (a > b)
        printf("%d is greater than %d\n", a, b);
    else if (a < b)
        printf("%d is less than %d\n", a, b);
    else …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.