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

S. Wave Form

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

Score: 0

CPU: 1s
Memory: 512MB

You will be given n. You have to draw following figures.
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 T line next. Each line contains a single integer n ( 0 < n < 50 )

Output
For each n you have to draw figures as described in problem statement. Print a blank line between consecutive test cases.

Sample

InputOutput
3 1 2 3 * * *** * * *** ***** *** *

Solution

#include<stdio.h>
int main()
{
    int i,s=1,t,j,l,n;
    scanf("%d",&t);
    for(i=1;i<=t;i++){
        scanf("%d",&n);
        s=n-1;
        for(j=1;j<=n;j++){
            for(l=1;l<=s;l++)
                printf(" ");
                s--;
            for(l=1;l<=2*j-1;l++)
                printf("*");
            printf("\n");
        }
        s=1;
        for(j=1;j<=n-1;j++){
            for(l=1;l<=s;l++)
                printf(" ");
            s++;
            for(l=1;l<=2*(n-j)-1;l++)
                printf("*");
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment