Sunday, September 5, 2024

Print Following Pattern of Pyramid

Example :
0
1 1 1
2 2 2 2 2
3 3 3 3 3 3 3
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=0;i<=9;i++)
     {
      for(j=0;j<(1+2*i);j++)
         printf("%d ",i);
     printf("\n");
     }
getch();
}

Explanation :
for(j=0;j<(1+2*i);j++)

  1. Outer for loop Indicates "How Many Lines is to be printed ?"
  2. Inner For Loop Tells "How many Numbers are printed on Single Line ?"
When i = 0
Number of Values Printed = 1 + 2i = 1 + 2(0) = 1


When i = 1
Number of Values Printed = 1 + 2i = 1 + 2(1) = 3

When i = 2
Number of Values Printed = 1 + 2i = 1 + 2(2) = 5

0 comments:

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email