-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path03_first_n_odd.c
43 lines (35 loc) · 872 Bytes
/
03_first_n_odd.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
// // Write a recursive function to print first N odd natural numbers.
// // Header Files
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
// // Function Declaration (Prototype)
void firstNOddNaturalNums(int);
// // Main Function Start
int main()
{
int n;
printf("\nEnter N to Print First N Odd Natural Numbers => ");
scanf("%d", &n);
if (n < 0)
{
puts("\n!!! Invalid Input, Plz Enter Positive Number...");
exit(0);
}
printf("\n>>>>>>> First %d Odd Natural Numbers <<<<<<<\n", n);
firstNOddNaturalNums(n);
putch('\n');
getch();
return 0;
}
// // Main Function End
// // Function Definition 👇👇
// // Recursive Function to Print First N Odd Natural Numbers
void firstNOddNaturalNums(int n)
{
if (n > 0)
{
firstNOddNaturalNums(n - 1);
printf("%d ", n * 2 - 1);
}
}