Pattern 3 (Id-3459)
sol:-
C-CODE:
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 questionsol:-
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;
}
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;
}
0 Comments