Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 5 June 2016

PROBLEM 18:

Write a C Program that prompts the user for a positive integer as input, printing the respective hollow triangle




















CODE:


#include <stdio.h>

int main()
{
    int i, j, n;

    //Reads number of rows to be printed from user
    printf("Enter value of n : ");
    scanf("%d", &n);

    for(i=1; i<=n; i++)
    {
        //Prints trailing spaces
        for(j=i; j<n; j++)
        {
            printf(" ");
        }

        //Prints hollow pyramid
        for(j=1; j<=(2*i-1); j++)
        {
            if(i==n || j==1 || j==(2*i-1))
            {
                printf("*");
            }
            else
            {
                printf(" ");
            }
        }

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

}

Program Output:






For more problems click here

No comments:

Post a Comment