Monday, April 22, 2019

Half pyramid

  • Problem Description

    Sam had a program for a full pyramid. But he didnt know that how to print half pyramid by using alphabets. So help him to write a program to print half pyramid using alphabets using increment operator
  • Test Case 1

    Input (stdin)
    G

    Expected Output
    A

    BB

    CCC

    DDDD

    EEEEE

    FFFFFF

    GGGGGGG
  • Test Case 2

    Input (stdin)
    B

    Expected Output
    A

    BB
Solution

#include <stdio.h>
int main()
{
    int i, j;
    char input, alphabet = 'A';
  scanf("%c",&input);

    for(i=1; i <= (input-'A'+1); ++i)
    {
        for(j=1;j<=i;++j)
        {
            printf("%c", alphabet);
        }
        ++alphabet;

        printf("\n");
    }
    return 0;
}

No comments:

Post a Comment

Parity

Problem Description Ram and Sita playing the parity game. Two types of parity are there. One is odd parity and next is even parity. Ram will...