#include <stdio.h> int main() { int x,n; printf("Enter n value "); scanf("%d",&n); if(n%2==0) { for(x=1;x<=n;x++) { if(x%2==0) { printf("%d\n",x); } } } else { for(x=1;x<=n;x++) { if(x%2!=0) { printf("%d\n",x); } } } return 0; }
Enter n value 20
2
4
6
8
10
12
14
16
18
20
Enter n value 21
1
3
5
7
9
11
13
15
17
19
21