C Saved Program: beautiful-terrain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
 int main()
{
  int n, c, k, space = 1;
   printf("Enter number of rows\n");
  scanf("%d", &n);
   space = n - 1;
   for (k = 1; k <= n; k++)
  {
    for (c = 1; c <= space; c++)
      printf("  ");
     space--;
     for (c = 1; c <= 2*k-1; c++)
      printf(" * ");
     printf("\n");
  }
   space = 1;
   for (k = 1; k <= n - 1; k++)
  {
    for (c = 1; c <= space; c++)
      printf("  ");
     space++;
     for (c = 1 ; c <= 2*(n-k)-1; c++)
      printf(" * ");
 
    printf("\n");
  }
   return 0;
}

Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs