Advertisement
Mr_kindle

Pattern1.c

Oct 30th, 2022 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. /* program to print in this question two numbers are skipped after encountering odd number
  2. 1 4
  3. 5
  4. 8
  5. 9
  6. 12 13 16 17
  7. 20
  8. 21
  9. 24
  10. 25
  11. 28
  12. 29
  13. 32 33 36 37 40 41*/
  14.  
  15. #include<stdio.h>
  16.  
  17. int main()
  18. {int n,i,m=1,j;
  19. int h_count,v_count;
  20. printf("Enter value of n: \n");
  21. scanf("%d",&n);
  22.  
  23. printf("\nHere is the list\n\n");
  24. for(i=1;i<=n;i++)
  25. /*h_count for horizontal range and v_count for vertical range*/
  26. {   h_count=2*m;v_count=3*m;
  27. /*To print horizontally*/
  28.      for(j=1;j<=h_count;j++)
  29.         {if(i<=n)//check whether i within the range or not
  30.             printf("%d ",i);
  31.             if(i%2!=0)//if odd skip 2 numbers
  32.             i+=2;
  33.             i++;
  34.         }
  35.         printf("\n");
  36.         /*to print vertically*/
  37.      for(j=1;j<=v_count;j++)
  38.     { if(i<=n)//check whether i is in the range or not
  39.         { printf("%d",i);
  40.             printf("\n");
  41.             if(i%2!=0)//if odd skip 2 numbers
  42.             i+=2;
  43.             i++;
  44.         }
  45.     }
  46.     i--;
  47.     m++;
  48.    
  49. } return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement