Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mansadixit authored Apr 25, 2022
1 parent baafbc0 commit 514cd26
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
26 changes: 26 additions & 0 deletions factorial.cpp
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;
}
23 changes: 23 additions & 0 deletions powerlinear.cpp
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);
}
24 changes: 24 additions & 0 deletions printdecreasing.cpp
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;
}
38 changes: 38 additions & 0 deletions printincreasing.cpp
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;
}
18 changes: 18 additions & 0 deletions printlogarithmic.cpp
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;
}
26 changes: 26 additions & 0 deletions printzigzag.cpp
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);
}

0 comments on commit 514cd26

Please sign in to comment.