Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* program to print in this question two numbers are skipped after encountering odd number
- 1 4
- 5
- 8
- 9
- 12 13 16 17
- 20
- 21
- 24
- 25
- 28
- 29
- 32 33 36 37 40 41*/
- #include<stdio.h>
- int main()
- {int n,i,m=1,j;
- int h_count,v_count;
- printf("Enter value of n: \n");
- scanf("%d",&n);
- printf("\nHere is the list\n\n");
- for(i=1;i<=n;i++)
- /*h_count for horizontal range and v_count for vertical range*/
- { h_count=2*m;v_count=3*m;
- /*To print horizontally*/
- for(j=1;j<=h_count;j++)
- {if(i<=n)//check whether i within the range or not
- printf("%d ",i);
- if(i%2!=0)//if odd skip 2 numbers
- i+=2;
- i++;
- }
- printf("\n");
- /*to print vertically*/
- for(j=1;j<=v_count;j++)
- { if(i<=n)//check whether i is in the range or not
- { printf("%d",i);
- printf("\n");
- if(i%2!=0)//if odd skip 2 numbers
- i+=2;
- i++;
- }
- }
- i--;
- m++;
- } return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement