Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void show (char **a , int n){
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++){
- cout<<a[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- int main(){
- int n;
- cin>>n;
- char ** a= new char *[2*n+1];
- for(int i=0;i<2*n+1;i++){
- a[i] = new char [2*n+1];
- }
- int k=2*n+1;
- int diamond=1;
- int space=1;
- int d2=k-2;
- for(int i=0;i<k;i++){
- // int diamond=1;
- if (i<(k-1)/2+1){ for(int j=0;j<k;j++){
- if (j<n){
- a[i][j]='.';
- }
- for(int d=0;d<diamond;d++) a[i][n+d]='*';
- if (j>n-1+diamond) a[i][j]='.';
- }
- n--;
- diamond+=2;
- }
- if ( i>= (k-1)/2+1){
- for(int j=0;j<k;j++){
- if (j<space ) a[i][j]='.';
- for(int d=space;d<=d2;d++){
- a[i][d]='*';
- }
- if ( j>=d2+1) a[i][j]='.';
- }
- space ++;
- d2--;
- }
- }
- show(a,k);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment