Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Monday 31 October 2016

R. Pyramid

Problem link
https://algo.codemarshal.org/contests/diu-122-fl16-termwork/problems/R

Score: 1

CPU: 1s
Memory: 512MB

You will be givenn. 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 heightn as described in problem statement. There will be blank line between consecutive test cases.

Sample

InputOutput
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