fork download
  1. #include <iostream>
  2. int a[30][30];
  3. void spiralPrint(int n)
  4. {
  5. int i,k=0,l=0;
  6. const char z='*';
  7. int m=n;
  8. for (i=l;i<n;++i)
  9. {
  10. a[k][i]=z;
  11.  
  12. }
  13. for (i=k;i<m;++i)
  14. {
  15. a[i][n-1]=z;
  16. }
  17. {
  18. for (i=n-1;i>=l;--i)
  19. {
  20. a[m-1][i]=z;
  21. }
  22. }
  23.  
  24. {
  25. for (i=m-1;i>=k;--i)
  26. {
  27. a[i][l]=z;
  28. }
  29. }
  30. }
  31.  
  32.  
  33.  
  34. int main()
  35. { int u;
  36. int y=3;
  37. std::cout<<"Enter the Limit:";
  38. std::cin>>u;
  39. std::cout<<"\n";
  40. for(int q=0;q<u;q++)
  41. {
  42. spiralPrint(y);
  43. y=y+2;
  44. }
  45. for (int i=0;i<y;i++)
  46. {for (int j=0;j<y;j++)
  47. {std::cout<<"\t"<<(char)a[i][j];
  48. }
  49. std::cout<<"\n";}
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0s 3464KB
stdin
3
stdout
Enter the Limit:
	*	*	*	*	*	*	*		
	*		*		*		*		
	*	*	*		*		*		
	*				*		*		
	*	*	*	*	*		*		
	*						*		
	*	*	*	*	*	*	*