Pattern 2 (Id-3458)
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:
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, j, rows;
scanf("%d",&rows);
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("*");
}
printf("\n");
}
return 0;
}
int main()
{
int i, j, rows;
scanf("%d",&rows);
for(i=rows; i>=1; --i)
{
for(j=1; j<=i; ++j)
{
printf("*");
}
printf("\n");
}
return 0;
}
0 Comments