Check if a pair of numbers is in ascending/descending order
C Practice Exercise
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:

For more Practice: Solve these Related Problems:
- Write a C program to check if three numbers provided by the user are in strictly increasing order.
- Write a C program to determine if a list of numbers is sorted in non-decreasing (ascending) order.
- Write a C program to verify whether two consecutive numbers in an array are in ascending or descending order.
- Write a C program to check if two numbers are in descending order, including cases with duplicate values.
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 and Language Statistics
- Weekly Trends and Language Statistics