Home > Backend Development > C++ > Write a program in C language to print a number pattern

Write a program in C language to print a number pattern

王林
Release: 2023-08-26 12:05:05
forward
1420 people have browsed it

Program Description

Print a numeric pattern by accepting a user-supplied number of lines.

Input: 5 lines

1
6 2
10 7 3
13 11 8 4
15 14 12 9 5
Copy after login

Algorithm

Print the pattern from the end of each Row
Complete the last column of each Row
Start from the Second Last Column of the second row
Repeat till the number of rows specified by the User.
Copy after login

Example

/*Program to print Numeric Pattern */
#include<stdio.h>
int main()
{
   int k, l, m, count=1;
   int rows;
   clrscr();
   printf("</p><p> Please enter the number of rows for the Numeric Pattern: ");
   scanf("%d",&rows);
   for (k = 1; k <= rows; k++) {
      m = count;
      for (l = 1; l <= k; l++) {
         printf("%d",m);
         m = m - (rows + l - k);
      }
      printf("</p><p>");
      count = count + 1 + rows - k;
   }
   getch();
   return 0;
}
Copy after login

Output

Write a program in C language to print a number pattern

Write a program in C language to print a number pattern

The above is the detailed content of Write a program in C language to print a number pattern. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template