fork download
  1. //Q54. Write a program to print the following pattern:
  2.  
  3. // *
  4. //***
  5. //*****
  6. //*******
  7. //*****
  8. //***
  9. //*
  10. #include <stdio.h>
  11.  
  12. int main() {
  13. int n = 4;
  14. for (int i = 1; i <= 2*n-1; i++) {
  15. int stars = i <= n ? 2*i-1 : 2*(2*n-i)-1;
  16. int spaces = (2*n-1 - stars)/2;
  17. for (int s = 0; s < spaces; s++) printf(" ");
  18. for (int j = 0; j < stars; j++) printf("*");
  19. printf("\n");
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
   *
  ***
 *****
*******
 *****
  ***
   *