R. Pyramid
Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/R
Score: 1
CPU: 1s
Memory: 512MB
CPU: 1s
Memory: 512MB
You will be given
n. You have to draw a * Pyramid of height n.
If
n == 1*
If
n == 2 *
***
If
n == 3 *
***
*****
Input
First you will be given a positive integer
T (1< T < 100), the number of test case. There will be Tline next. Each line contains a single integer n ( 0 < n < 50 ).
Output
For each n you have to draw a Pyramid of height
For each n you have to draw a Pyramid of height
n as described in problem statement. There will be blank line between consecutive test cases.Sample
| Input | Output |
|---|---|
| 3 1 2 3 | * * *** * *** ***** |
Solution
#include<stdio.h>
int main()
{
int D,A,S,Y,W,C,X;
scanf("%d",&W);
for(D=1;D<=W;D++){
if(D!=1){
printf("\n");
}
scanf("%d",&X);
C=X;
for(A=1;A<=X;A++){
for(S=1;S<C;S++){
printf(" ");
}
C--;
for(Y=1;Y<=2*A-1;Y++){
printf("*");
}
printf("\n");
}
}
return 0;
}
No comments:
Post a Comment