C Examples

WAP in C to read 6 digits and find out if they are in a strictly ascending order

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X