fork download
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
  5. C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
  6. Code, Compile, Run and Debug online from anywhere in world.
  7.  
  8. *******************************************************************************/
  9. #include <iostream>
  10. #include<algorithm>
  11.  
  12. using namespace std;
  13.  
  14. void printPattern(int n)
  15. {
  16.  
  17. //handle negative and even number cases
  18. if(n<=2 || n%2==0)
  19. {
  20. cout<<"Invalid case!";
  21. return;
  22. }
  23. //run the outer loop to print the row wise
  24. for(int i=0;i<n+1;i++)
  25. {
  26. // inner loop to column wise
  27. for(int j=0;j<n-1;j++)
  28. {
  29. cout<<" "<<" ";
  30. }
  31. cout<<"e"<<" ";
  32. for(int j=0;j<n+2;j++)
  33. {
  34. if(i==0)
  35. {
  36. cout<<"*"<<" ";
  37. }
  38. }
  39. for(int j=0;j<n;j++)
  40. {
  41. if(i==(n/2)+1)
  42. {
  43. cout<<"*"<<" ";
  44. }
  45. }
  46. cout<<endl;
  47. }
  48. //At the end print last pattern of last row
  49. for(int i=0;i<n-1;i++)
  50. {
  51. cout<<"*"<<" ";
  52. }
  53. cout<<"e";
  54. }
  55.  
  56. int main()
  57. {
  58. int n;
  59. cin>>n;
  60. //calling function to print the pattern
  61. printPattern(n);
  62. return 0;
  63. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Invalid case!