fork download
  1. #include <iostream>
  2.  
  3. void print_letters(int letters, int limit)
  4. {
  5. for (int i = 0; i < (limit - letters) / 2; i++)
  6. {
  7. std::cout << ' ';
  8. }
  9.  
  10. for (int i = 0; i < letters; i++)
  11. {
  12. std::cout << char(i + 'A');
  13. }
  14.  
  15. std::cout << std::endl;
  16. }
  17.  
  18. void recursion_rocks(int letters, int limit)
  19. {
  20. print_letters(letters, limit);
  21.  
  22. if (letters != limit)
  23. {
  24. recursion_rocks(letters + 2, limit);
  25. print_letters(letters, limit);
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. std::cout << "Enter an odd number:" << std::endl;
  32. int number;
  33. std::cin >> number;
  34.  
  35. recursion_rocks(1, number);
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0s 3344KB
stdin
11
stdout
Enter an odd number:
     A
    ABC
   ABCDE
  ABCDEFG
 ABCDEFGHI
ABCDEFGHIJK
 ABCDEFGHI
  ABCDEFG
   ABCDE
    ABC
     A