Problem statement:
Print the pattern.
Input:
9
Output:
code:
#include <stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
int k=(n*2)-1;
int l=1,r=k,mid=(k/2)+1,m1=mid,m2= mid;
for(i=1;i<=n;i++)
{ for(j=1;j<=k;j++)
{
if(j>=l && j<=r)
{
if(i<(n/2)+1)
{
if(i!=0 && (j>m1 && j<m2))
{
printf(" ");
}
else
printf("*");
}
else
printf("*");
}
else
printf(" ");
}
l=l+1;
r=r-1;
if(i<mid)
{m2++; m1--;}
printf("\n");
}
return 0;
}
https://books.google.co.in/books?id=H3ZM_gp-NfwC&pg=PA93&lpg=PA93&dq=B,C,D,F,G,H+and+J+are+seven+students+studying+in+three+colleges+P,Q+and+R&source=bl&ots=uWO2g-jlqT&sig=k3Qyx9e_-8A1gnsVJmtDjpOeTrA&hl=en&sa=X&ved=0ahUKEwjSna3L1tvNAhUHvo8KHejBBncQ6AEIHjAB#v=onepage&q=B%2CC%2CD%2CF%2CG%2CH%20and%20J%20are%20seven%20students%20studying%20in%20three%20colleges%20P%2CQ%20and%20R&f=false
ReplyDelete