fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char** argv) {
  5.  
  6. int middle, spaceCount, starCount;
  7.  
  8. int num = 5;
  9.  
  10. middle = (num-1) / 2;
  11.  
  12. for (int i = 0; i < num; i++){
  13.  
  14. spaceCount = abs(middle - i);
  15. starCount = num - 2*abs(middle - i);
  16.  
  17. for(int c = 0; c < spaceCount; c++)
  18. printf(" ");
  19.  
  20. for(int c = 0; c < starCount; c++)
  21. printf("*");
  22.  
  23. printf("\n");
  24. }
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 2112KB
stdin
Standard input is empty
stdout
  *
 ***
*****
 ***
  *