fork download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. int n;
  5. scanf("%d", &n);
  6.  
  7. /// first half
  8. int space = n-1;
  9. int star = 1;
  10. for(int i=1; i<=n; i++)
  11. {
  12. for(int j=1; j<=space; j++)
  13. {
  14. printf(" ");
  15. }
  16.  
  17. for(int j=1; j<=star; j++)
  18. {
  19. printf("*");
  20. }
  21.  
  22. printf("\n");
  23.  
  24. /// preparing for the next row
  25. star = star + 2;
  26. space = space - 1;
  27. }
  28.  
  29. /// second half
  30. space = 1;
  31. star = ((2*n)-1) - 2; /// last line of the first half has (2*n)-1 stars, and the first line of the second half will have ((2*n)-1) - 2 stars
  32.  
  33. for(int i=1; i<n; i++)
  34. {
  35. for(int j=1; j<=space; j++)
  36. {
  37. printf(" ");
  38. }
  39.  
  40. for(int j=1; j<=star; j++)
  41. {
  42. printf("*");
  43. }
  44.  
  45. printf("\n");
  46.  
  47. /// preparing for the next row
  48. star = star - 2;
  49. space = space + 1;
  50. }
  51. }
  52.  
Success #stdin #stdout 0s 5312KB
stdin
5
stdout
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *