-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
baafbc0
commit 514cd26
Showing
6 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int facto = 1; | ||
|
||
int fact(int n) | ||
{ | ||
if (n == 1) | ||
{ | ||
return facto; | ||
} | ||
else | ||
{ | ||
facto = facto * n; | ||
return fact(n - 1); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int i, j, n; | ||
cout << "Enter the number: " << endl; | ||
cin >> n; | ||
cout << "Factorial: " << fact(n); | ||
cout << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int i = 1, mul = 1; | ||
|
||
void power(int x, int n) | ||
{ | ||
if (i <= n) | ||
{ | ||
mul = mul * x; | ||
i++; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int x, n; | ||
cout << "Enter the number: " << endl; | ||
cin >> x; | ||
cout << "Enter the power: " << endl; | ||
cin >> n; | ||
cout<<power(x, n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int dec(int n) | ||
{ | ||
if (n == 1) | ||
{ | ||
return 1; | ||
} | ||
else | ||
{ | ||
cout << n << endl; | ||
return dec(n - 1); | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int i, j, n; | ||
cout << "Enter the number: " << endl; | ||
cin >> n; | ||
cout << dec(n); | ||
cout << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int N = 10; | ||
int n = 1; | ||
|
||
void fun1(); | ||
void fun2(); | ||
|
||
void fun1() | ||
{ | ||
if (n <= N) | ||
{ | ||
cout << n << " "; | ||
n++; | ||
fun2(); | ||
} | ||
else | ||
return; | ||
} | ||
|
||
void fun2() | ||
{ | ||
if (n <= N) | ||
{ | ||
cout << n << " "; | ||
n++; | ||
fun1(); | ||
} | ||
else | ||
return; | ||
} | ||
|
||
int main() | ||
{ | ||
fun1(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <cmath> | ||
using namespace std; | ||
|
||
double fact(int n) | ||
{ | ||
if (n == 1) | ||
{ | ||
return 0; | ||
} | ||
return fact(n - 1) + log(n); | ||
} | ||
|
||
int main() | ||
{ | ||
int N = 3; | ||
cout << fact(N) << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void zigzag(int n) | ||
{ | ||
if (n == 1) | ||
{ | ||
cout << "1 1 1"; | ||
} | ||
else if (n == 2) | ||
{ | ||
cout << "2 1 1 1 2 1 1 1 2"; | ||
} | ||
else | ||
{ | ||
cout << "3 2 1 1 1 2 1 1 1 2 3 2 1 1 1 2 1 1 1 2 3"; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
cout << "Enter a number: " << endl; | ||
cin >> n; | ||
zigzag(n); | ||
} |