C Exercises: Find Ascending or Descending order from a pair of numbers
Check if two integers are in ascending or descending order
Write a C program that accepts a pair of numbers from the user and prints "Ascending order" if the two numbers are in ascending order, otherwise prints, "Descending order".
Sample Solution:
C Code:
#include <stdio.h>
int main () {
int a, b;
// Prompt user for input
printf("Input two pairs values (integer values):\n");
// Read two integer values from user and store them in 'a' and 'b'
scanf("%d %d", &a, &b);
// Check if 'a' is not equal to 'b'
if (a != b) {
// Check if 'b' is greater than 'a'
if (b > a) {
printf("Ascending order\n"); // Print message for ascending order
}
else {
printf("Descending order\n"); // Print message for descending order
}
}
return 0; // End of program
}
Sample Output:
Input two pairs values (integer values): 12 35 Ascending order
Sample Output:
Input two pairs values (integer values): 65 25 Descending order
Flowchart:
C programming Code Editor:
Previous: Write a C program that accepts a pair of numbers from the user and print the sequence from the lowest to highest number. Also, print the average value of the sequence.
Next: Write a C program that read two integers and dividing the first number by second, print the result of this division with two digits after the decimal point and print "Division not possible..!" if the division is not possible.
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