Sunday, 16 April 2017

Program to print pattern using for loop

Program to print pattern using for loop

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5



#include<stdio.h>
void main()
{
                 int i,j,row;
                printf("Enter the number of rows you want:");
                scanf("%d",&row);
                 for(i=1;i<=row;i++)
                {
                                for(j=1;j<=i;j++)
                                {
                                                printf("%d ",i);
                                }
                                printf("\n");
                }  
}

Output:
Enter the number of rows you want: 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

No comments:

Post a Comment