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
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;
}
|
Last Updated :
01 Jun, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...