tungggg

Diamond

Feb 27th, 2022
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. void show (char **a , int n){
  4. for(int i=0;i<n;i++){
  5. for(int j=0;j<n;j++){
  6. cout<<a[i][j]<<" ";
  7. }
  8. cout<<endl;
  9. }
  10. }
  11. int main(){
  12. int n;
  13. cin>>n;
  14. char ** a= new char *[2*n+1];
  15. for(int i=0;i<2*n+1;i++){
  16. a[i] = new char [2*n+1];
  17. }
  18. int k=2*n+1;
  19. int diamond=1;
  20. int space=1;
  21. int d2=k-2;
  22. for(int i=0;i<k;i++){
  23. // int diamond=1;
  24. if (i<(k-1)/2+1){ for(int j=0;j<k;j++){
  25. if (j<n){
  26. a[i][j]='.';
  27. }
  28. for(int d=0;d<diamond;d++) a[i][n+d]='*';
  29. if (j>n-1+diamond) a[i][j]='.';
  30.  
  31. }
  32. n--;
  33. diamond+=2;
  34. }
  35.  
  36. if ( i>= (k-1)/2+1){
  37. for(int j=0;j<k;j++){
  38. if (j<space ) a[i][j]='.';
  39. for(int d=space;d<=d2;d++){
  40. a[i][d]='*';
  41. }
  42. if ( j>=d2+1) a[i][j]='.';
  43. }
  44. space ++;
  45. d2--;
  46. }
  47.  
  48. }
  49. show(a,k);
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment