Webkul Interview Experience | Pattern Question

**Write the code for the pattern given below:- 
*Instructions : 
? Time duration is 60 Mins 
? The pattern must be dynamic. It should work for any odd numbers.( Excluding 
1 and any negative numbers ) 
? It should not run for even numbers.
Examples: 
 

Input :For n=3 
Output :
   
 @@@
  @
***
* *
* *


Input :For n=5
Output :
  @@@@@
   @@@
    @
*****
*   *
*   *
*   *
*   *

 

CPP

filter_none

edit
close

play_arrow

link
brightness_4
code

int main()
{
  int n,i,j;
printf("Enter Input:");
scanf("%d",&n);
if(n<1||n%2==1)
{
return 0;
}
for(i=0;i<n/2;i++)
{
  for(j=0;j<n/2;j++)
  {
    printf(" ");
  }
  for(j=0;j<i;j++)
  {
    printf(" ");
  }
  for(j=0;j<n-(2*i);j++)
  {
    printf("@");
  }
printf("\n");
}
for(i=0;i<n;i++)
{
   for(j=0;j<n;j++)
   {
     if(i==0||j==0||j==n-1)
       printf("*");
     else
       printf(" "):
   }
printf("\n");
}
  return 0;

chevron_right


 
 


Write your Interview Experience or mail it to contribute@geeksforgeeks.org

My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.