Hollow Diamond Pattern(Pattern 6)

Plesae provide one more sample output for this question as my code passing one test case but failing other one, but it create correct result according to me.

hi @akshatjain4545 buddy refer

Hello @talhashamim001, sr thats not the same que my que name is hollow diamond pattern(pattern 6)

@talhashamim001 please help

hi @akshatjain4545 its diamond shape u are making it plus shape
eg for 7 notice the difference

*	*	*	*	*	*	*	
*	*	*		*	*	*	
*	*				*	*	
*						*	
*	*				*	*	
*	*	*		*	*	*	
*	*	*	*	*	*	*	

oohk thanks @talhashamim001



#include<iostream>
using namespace std;
int main(){
int i,j,k=0,n;
     cin>>n;
     for(i=0;i<n;i++)
     {
          if(i==0||i==n-1)
          {
               for(j=0;j<n;j++)
                    cout<<"*\t";
          }
          else if(i<=n/2)
          {
               for(j=0;j<(n/2)-i+1;j++)
               cout<<"*\t";
               for(j=0;j<2*i-1;j++)
               cout<<"\t";
               for(j=0;j<(n/2)-i+1;j++)
               cout<<"*\t";
               if(i==n/2)
                    k=2;
          }
          else
          {
               for(j=0;j<k;j++)
                    cout<<"*\t";
               for(j=0;j<n-(2*k);j++)
                    cout<<"\t";
               for(j=0;j<k;j++)
                    cout<<"*\t";
               k++;
          }
          cout<<"\n";
     }
	return 0;
}
1 Like