FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
C-Code-Examples/Iteration_Recursion.cpp at master · Derrick1908/C-Code-Examples · GitHub
Derrick1908
/
C-Code-Examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
C-Code-Examples
/
Iteration_Recursion.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (27 loc) · 817 Bytes
Breadcrumbs
C-Code-Examples
/
Iteration_Recursion.cpp
Copy path
File metadata and controls
35 lines (27 loc) · 817 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
stdio.h
>
#
include
<
conio.h
>
int
factorial
(
int
);
/*
Recursive Function
*/
int
factorial_iter
(
int
);
void
main
()
{
int
num;
printf
(
"
\n
Enter the Number ::
"
);
scanf_s
(
"
%d
"
, &num);
printf
(
"
\n
The Factorial of %d through Recursion is :: %d
"
, num,
factorial
(num));
printf
(
"
\n
The Factorial of %d through Iteration is :: %d
"
, num,
factorial_iter
(num));
_getch
();
}
int
factorial
(
int
n)
/*
Note that a Recursive function has to have an if statement in order to end
*/
{
/*
otherwise it would go into an infinite loop. No Loop is permitted in a recursive function
*/
if
(n ==
0
)
return
1
;
else
return
n*
factorial
(n -
1
);
}
int
factorial_iter
(
int
n)
{
int
i, fact =
1
;
for
(i = n; i >=
1
; i--)
fact = fact * i;
return
fact;
}
Back
|
FazBrowse Home
|
New Git URL