Home C Programming Language / Programs / Program to print the given number pattern reverse 6777777 5677777 4567777 3456777 2345677 1234567
🚀 Programming Example

Program to print the given number pattern reverse
6777777
5677777
4567777
3456777
2345677
1234567
 

👁 1,567 Views
💻 Practical Program
📘 Step Learning
Program to print the given number pattern reverse

💻 Program Code

/**
 * C program to print number pattern
 * www.atnyla.com
 */

#include <stdio.h>

int main()
{
    int rows, cols, i, j;

    /* Input rows and columns from user */
    printf("Enter number of rows: ");
    scanf("%d", &rows);
    printf("Enter number of columns: ");
    scanf("%d", &cols);

    for(i=rows; i>=1; i--)
    {
        for(j=i; j<=cols; j++)
        {
            printf("%d", j);
        }

        for(j=i; j>1; j--)
        {
            printf("%d", cols);
        }

        printf("\n");
    }

    return 0;
}
                        

🖥 Program Output

Enter number of rows: 6
Enter number of columns: 7
6777777
5677777
4567777
3456777
2345677
1234567
Press any key to continue . . .
                            

📘 Explanation

Required knowledge

Basic C programming, Loop

Logic to print the given number pattern

Before we get into detail of printing these two patterns I assume that you all must be aware of basic number pattern printing, if not I recommend you to go through some previous number pattern to get yourself acquainted.

 

12345
23455
34555
45555
55555

 

Now, considering this pattern have an eye to this pattern carefully you will notice two separate patterns here. The two separate patterns are:

Now logic to print the both patterns separately is relatively easier then whole pattern at once.

  1. Run an outer loop from 1 to max-column (where max-column is total number of columns in our case its 5).
  2. Initialize the inner loop from the current row till max-column.
  3. Inside inner loop print the current column.
  4. Run another inner loop after the termination of loop stated in step 2. Initialize it from current row till 1. And print max-column inside this loop.

And you are done. Lets, now implement this on code.

Program to print the giv

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.