0
1.2kviews
Generate the following pattern of digits using nested loops

enter image description here


Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 10M

Year: Dec 2015

1 Answer
0
3views

enter image description here

#include<stdio.h>
void main()
{
int i,space,rows,k=0,count=0,count1=0;
   printf("Enter the number of rows: ");
   scanf("%d",&rows);
for(i=1;i<=rows;++i)
{
for(space=1;space<=rows-i;++space)
{
          printf("  ");
++count;
}
while(k!=2*i-1)
{
if(count<=rows-1)
{
             printf("%d ",(i+k));
++count;
}
else
{
++count1;
              printf("%d ",(i+k-2*count1));
}
++k;
}
        count1=count=k=0;
        printf("\n");
}
getche(); }

(ii)

#include<stdio.h>
int main()
{
int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
for(i=1;i<=rows;++i)
{
for(j=1;j<=i;++j)
{
           printf("* ");
}
        printf("\n");
}
return0; }
Please log in to add an answer.