C Program to Print Matrix Pattern of Stars and Numbers

Here, I wish to share the article with the topic of “C Program to Print Matrix Pattern of Stars and Numbers”. Let’s jump on to this article directly.

C Program to Print Matrix Pattern of Stars and Numbers

C Program to Print Matrix Pattern of Stars and Numbers

Program Code

#include <stdio.h>
int main()
{
  int n, p = 1, a[100][100], j, m, k, r;

  scanf("%d", &r);

  for (j = 1; j <= r; j++) {
    m = 0;
    n = j;
    for (k = 1; k <= j; k++)
      a[m++][--n] = p++;
  }

  for (j = 1; j <= r-1; j++) {
    m = j;
    n = r-1;
    for (k = 1; k<= r-j; k++)
      a[m++][n--] = p++;
  }

  for (j = 0; j <= r-1; j++) {
    for (k = 0; k <= r-1; k++)
      printf("%d ", a[j][k]);
    printf("n");
  }

  return 0;
}

Final Words

I hope this article helps you to learn “C Program to Print Matrix Pattern of Stars and Numbers”. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment