-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path17_first_n_even_natural_reverse.c
94 lines (79 loc) · 1.97 KB
/
17_first_n_even_natural_reverse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// // C program to print the first N even natural numbers in reverse order
// // Header Files
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// // Main Function Start
int main()
{
int n;
printf("\nEnter N to Print First N Even Natural Numbers In Reverse Order => ");
scanf("%d", &n);
// // Handling Invalid Input
if (n < 0)
{
printf("!!! Invalid Input .....");
exit(0);
}
printf("\n>>>>>>>> First %d Even Natural Numbers In Reverse Order <<<<<<<<\n", n);
// // 1st Approach (using while loop)
int i = n;
while (i)
{
printf("\n%d", i * 2);
i--;
}
// // 2nd Approach (using while loop)
// // int i = n * 2;
// // while (i)
// // {
// // printf("\n%d", i);
// // i -= 2;
// // }
// // 3rd Approach (using while loop)
// // int i = n * 2;
// // while (i)
// // {
// // if (i % 2 == 0)
// // printf("\n%d", i);
// // i--;
// // }
// // 4th Approach (using do-while loop)
// // int i = n;
// // do
// // {
// // printf("\n%d", i * 2);
// // i--;
// // } while (i);
// // 5th Approach (using do-while loop)
// // int i = n * 2;
// // do
// // {
// // printf("\n%d", i);
// // i -= 2;
// // } while (i);
// // 6th Approach (using do-while loop)
// // int i = n * 2;
// // do
// // {
// // if (i % 2 == 0)
// // printf("\n%d", i);
// // i--;
// // } while (i);
// // 7th Approach (using for loop)
// // for (int i = n; i; i--)
// // printf("\n%d", i * 2 );
// // 8th Approach (using for loop)
// // for (int i = n * 2; i ; i -= 2)
// // printf("\n%d", i);
// // 9th Approach (using for loop)
// // for (int i = n * 2; i; i--)
// // {
// // if (i % 2 == 0)
// // printf("\n%d", i);
// // }
printf("\n");
getch();
return 0;
}
// // Main Function End