Loops (pattern3) ID-3459

Pattern 3 (Id-3459)

Given the value of ‘n’, develop an algorithm and write a C program to print the following pattern. When the value of ‘n’ is 5, the pattern will look as follows:

     *

   ***

  *****

 *******

*********

Input Format

First line contains the value of ‘n’



Output Format
Print the pattern given in the question
sol:-
C-CODE: 
#include <stdio.h>
int main()
{
    int i, space, rows, k=0;
    scanf("%d",&rows);
    for(i=1; i<=rows; ++i, k=0)
    {
        for(space=1; space<=rows-i; ++space)
        {
            printf("  ");
        }
        while(k != 2*i-1)
        {
            printf("*");
            ++k;
        }
        printf("\n");
    }
    return 0;
}

Post a Comment

0 Comments