The Program in C to read 6 digits and find out if they are in a strictly ascending order is given below:
#include <stdio.h>
int main() {
int num, prev, i;
printf("Enter 6 digits: ");
scanf("%d", &prev);
for (i = 1; i < 6; i++) {
scanf("%d", &num);
if (num <= prev) {
printf("The digits are not in strictly ascending order.\n");
return 0;
}
prev = num;
}
printf("The digits are in strictly ascending order.\n");
return 0;
}
Output:
Enter 6 digits: 7
8
9
10
12
5
The digits are not in strictly ascending order.
Pro-Tips💡
This program takes 6 digits as input, and uses a for loop to read each digit. It uses a variable prev
to keep track of the previous digit read, and compares the current digit to the previous digit.
If the current digit is less than or equal to the previous digit, the program outputs “The digits are not in strictly ascending order”
and exits, otherwise it updates the prev
variable and continues with the next iteration of the loop.
If the loop completes successfully, it means that the digits are in strictly ascending order, it then prints “The digits are in strictly ascending order.”
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.