Thursday, October 24, 2019

Pattern in c using loop(hackerrank medium level question)


Hello guys this is code for hakerrank pattrn question ...30 points

#include <stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
for(i=n;i>0;i--)
{ for(j=n;j>0;j--)
{  if(i==j)
printf("%d",i);
else if(j<i)
printf("%d",i);
else printf("%d",j);
}
for(j=2;j<=n;j++)

{ if(i==j)
printf("%d",i);
else if(j<i)
printf("%d",i);
else printf("%d",j);

 }
printf("\n");


}
for(i=2;i<=n;i++)
{ for(j=n;j>=1;j--)
{  if(i==j)
printf("%d",i);
else if(j<i)
printf("%d",i);
else printf("%d",j);
}
for(j=2;j<=n;j++)

{ if(i==j)
printf("%d",i);
else if(j<i)
printf("%d",i);
else printf("%d",j);

 }
printf("\n");


}
return 0;
}

No comments:

Implement stsStr Leetcode solution

  28.   Implement strStr() Easy Implement  strStr() . Given two strings  needle  and  haystack , return the index of the first occurrence of...