Time spent here:

Wednesday, 15 June 2016

Print the pattern.

Input:
5
 
Output:
123454321
1234*4321
123***321
12*****21
1*******1
 
code:
 
#include <stdio.h>

int main()
{
   int n,i,j,k,l,m;
   scanf("%d",&n);
   m=2*(n);
   l=n;k=n;
   for(j=1;j<=n;j++){
   for(i=1;i<m;i++)
   {
      if(j==1){
       if(i<=n)
         printf("%d",i);
       else
        printf("%d",m%i);
      }
      else
      {
          if(i>l && i<k || l==k)
            printf("*");
          else
            {
                 if(i<=n)
                    printf("%d",i);
                 else
                     printf("%d",m%i);
            }
      }
   }
   printf("\n");
   l--;k++;
   }
    return 0;
}
 
sample testcase:
 
Output

1234321
123*321
12***21
1*****1
Input

4
 
view this at:https://code.hackerearth.com/97e078w 

No comments:

Post a Comment