C Exercises: Check whether two numbers in a pair is in ascending order or descending order
C Basic Declarations and Expressions: Exercise-35 with Solution
Write a C program to check if two numbers in a pair are in ascending order or descending order.
C Code:
#include <stdio.h>
int main() {
int x, y, i, total = 0; // Declare variables for user input and calculations
printf("\nInput a pair of numbers (for example 10,2 : 2,10):");
printf("\nInput first number of the pair: ");
scanf("%d", &x); // Read the first number
printf("\nInput second number of the pair: ");
scanf("%d", &y); // Read the second number
if (x > y) {
printf("The pair is in descending order!"); // If x is greater than y, print message for descending order
} else {
printf("The pair is in ascending order!"); // Otherwise, print message for ascending order
}
printf("\n");
return 0;
}
Sample Output:
Input a pair of numbers (for example 10,2 : 2,10): Input first number of the pair: 10 Input second number of the pair: 2 The pair is in descending order!
Flowchart:

C Programming Code Editor:
Previous: Write a C program to compute the sum of consecutive odd numbers from a given pair of integers.
Next: Write a C program to read a password until it is correct. For wrong password print "Incorrect password" and for correct password print "Correct password" and quit the program. The correct password is 1234.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join