Contact Learn C
Copy

Program 297: Numerical Pattern 6 to display as Given Pattern

Program 297: Numerical Pattern 6 to display as Given Pattern
 
//              1
//           2  3
//        3  5  7
//     4  7 10 13
//  5  9 13 17 21
//For 5 rows
#include<stdio.h>
main()
{
 int i,j,k,sum,rows,count;
 printf("Enter number of rows\n");
 scanf("%d",&rows);
 for(i=1;i<=rows;i++)
 {
  //For giving spaces in correct formation
  //Like in first row it will take  12 spaces before 1 excluding 3 spaces occupied by digit 1
  //Second row it will take 15-(i*3)--->15-(2*3)=9 spaces excluding 6 spaces (3 occupied by '1' and 3 occupied by '1'
  //If still not able to understand Comment it at down
  count=rows*3;
  count-=(i)*3;
  for(k=count;k>=1;k--)
  printf(" ");
  sum=i;
  for(j=1;j<=i;j++)
  {
   // %3d for Taking as each digit occupying 3 significant places ex.if digit 3 is there then _ _ 3 and if 10 is there _ 10 
   //To get correct spaces in between digits
   printf("%3d",sum);
   sum=sum+(i-1);
  }
  printf("\n");
  
 }
}
Explanation:

//Coming Soon...

Output:
Pattern to display row wise Addition.Numerical Pattern 6

Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide