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
: ");
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))
{
}
else
{
printf("
");
}
}
printf("\n");
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment