-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from twowaits/master
new
- Loading branch information
Showing
84 changed files
with
3,127 additions
and
68 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
8thoct_c++_program to find gcd of factorial of two number.cpp
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 <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int factorial(int x) | ||
{ | ||
if (x <= 1) | ||
return 1; | ||
int res = 2; | ||
for (int i = 3; i <= x; i++) | ||
res = res * i; | ||
return res; | ||
} | ||
|
||
int gcdOfFactorial(int m, int n) | ||
{ | ||
return factorial(min(m, n)); | ||
} | ||
|
||
int main() | ||
{ | ||
int m = 5, n = 9; | ||
cout << gcdOfFactorial(m, n); | ||
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,25 @@ | ||
// Problem to find the GCD of the factorials of the two given numbers | ||
// The below code will surely work till the lesser of the two numbers entered is less than 17 , as finding factorial of such large numbers is really hectic in languages like C and C++ | ||
|
||
#include <stdio.h> | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ long int fact(int ); | ||
unsigned long long int n1,n2,p; | ||
cout<<"enter the first number"<<endl;//enter the value b/w 1 to 16 | ||
cin>>n1; | ||
cout<<"enter the second element"<<endl; | ||
cin>>n2; | ||
p = min(n1,n2); | ||
cout<<"GCD of the two numbers is"<<fact(p); | ||
return 0; | ||
} | ||
|
||
long int fact(int n) { // Factorial using recurssion | ||
if (n>=1) | ||
return n*fact(n-1); | ||
else | ||
return 1; | ||
} |
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,29 @@ | ||
#include <stdio.h> | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
unsigned long long int n1,n2,f1=1,i,p; | ||
cout<<"enter the first number"<<endl;//enter the value b/w 1 to 16 | ||
cin>>n1; | ||
cout<<"enter the second number"<<endl; | ||
cin>>n2; | ||
if(n1>n2) | ||
{ | ||
p=n2; | ||
} | ||
else | ||
{ | ||
p=n1; | ||
} | ||
for(i=1;i<=p;i++) | ||
{ | ||
f1=f1*i; | ||
} | ||
|
||
cout<<"the GCD of two number"<<" "<<n1<<" "<<n2<<" is!!"<<endl; | ||
cout<<f1; | ||
|
||
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,24 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int factorial(int x) | ||
{ | ||
if (x <= 1) | ||
return 1; | ||
int res = 2; | ||
for (int i = 3; i <= x; i++) | ||
res = res * i; | ||
return res; | ||
} | ||
|
||
int gcdOfFactorial(int m, int n) | ||
{ | ||
return factorial(min(m, n)); | ||
} | ||
|
||
int main() | ||
{ | ||
int m = 5, n = 9; | ||
cout << gcdOfFactorial(m, n); | ||
return 0; | ||
} |
24 changes: 24 additions & 0 deletions
24
9thoct_c++_program to find gcd of factorial of two number.cpp
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 <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int factorial(int x) | ||
{ | ||
if (x <= 1) | ||
return 1; | ||
int res = 2; | ||
for (int i = 3; i <= x; i++) | ||
res = res * i; | ||
return res; | ||
} | ||
|
||
int gcdOfFactorial(int m, int n) | ||
{ | ||
return factorial(min(m, n)); | ||
} | ||
|
||
int main() | ||
{ | ||
int m = 5, n = 9; | ||
cout << gcdOfFactorial(m, n); | ||
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,45 @@ | ||
// C++ code to demonstrate star pattern | ||
// Author: Siddharth Shrivastava, GitHub: @Siddharth2430 | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Function to demonstrate printing pattern | ||
void hollow_pyra(int n) | ||
{ | ||
// Number of spaces | ||
int i, j, k = n; | ||
|
||
// Outer loop to handle number of rows | ||
// n in this case | ||
for (i = 1; i < n; i++) { | ||
|
||
// Inner loop for columns | ||
for (j = 1; j <= n; j++) { | ||
|
||
// Condition to print star pattern | ||
if(j>k && j<n) | ||
cout<<" "; | ||
if (j == k || j == n) | ||
{ | ||
cout <<"* "; | ||
} | ||
else | ||
cout << " "; | ||
} | ||
k--; | ||
cout << "\n"; | ||
} | ||
for (i = 1; i <= n; i++) | ||
cout << "* "; | ||
} | ||
|
||
// Driver Code | ||
int main() | ||
{ | ||
int n=0; | ||
cout<<"Enter Number Of Rows = "; | ||
cin>>n; | ||
// Function Call | ||
hollow_pyra(n); | ||
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,22 @@ | ||
#include <iostream> | ||
#include<cmath> | ||
using namespace std; | ||
int main(){ | ||
int i,j,k,n; | ||
cin>>n; | ||
for(i=0;i<n;i++){ | ||
for(j=0;j<2*n;j++){ | ||
if(i+j==(n-1) || abs(i-j)==n-1){ | ||
cout<<"*"; | ||
} | ||
else if(i==n-1 && j%2==0){ | ||
cout<<"*"; | ||
} | ||
else{ | ||
cout<<" "; | ||
} | ||
} | ||
cout<<"\n"; | ||
} | ||
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,54 @@ | ||
#include<iostream> | ||
using namespace std; | ||
int main() | ||
{ | ||
int n; | ||
cin>>n; | ||
int row=0; | ||
int nsp=n-1; | ||
int nmsp=row+1; | ||
while(row<n) | ||
{ | ||
int csp=0; | ||
|
||
while(csp<nsp) | ||
{ | ||
cout<<" "; | ||
csp++; | ||
} | ||
nsp--; | ||
if(row==0) | ||
{ | ||
cout<<"*"; | ||
} | ||
else if(row==n-1) | ||
{ | ||
int cns=0; | ||
int nss=n-1; | ||
while(cns<nss) | ||
{ | ||
cout<<"* "; | ||
cns++; | ||
} | ||
cout<<"*"<<endl; | ||
} | ||
else | ||
{ | ||
cout<<"*"; | ||
int cmsp=0; | ||
|
||
while(cmsp<nmsp) | ||
{ | ||
cout<<" "; | ||
cmsp++; | ||
} | ||
|
||
cout<<"*"; | ||
nmsp+=2; | ||
} | ||
row++; | ||
cout<<endl; | ||
} | ||
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,42 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n; | ||
cin >> n; | ||
int count = 1; | ||
|
||
for (int i = 1; i <= n; i++) | ||
{ | ||
if (i != n) | ||
{ | ||
for (int j = n - i; j > 0; j--) | ||
{ | ||
cout << " "; | ||
} | ||
cout << "*"; | ||
if (i > 1) | ||
{ | ||
|
||
for (int k = 1; k <= count; k++) | ||
{ | ||
cout << " "; | ||
} | ||
count += 2; | ||
cout << "*"; | ||
} | ||
cout << endl; | ||
} | ||
if (i == n) | ||
{ | ||
for (int i = 0; i < n; i++) | ||
{ | ||
cout << "*" | ||
<< " "; | ||
} | ||
} | ||
} | ||
cout << endl; | ||
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,24 @@ | ||
#include <iostream> | ||
using namespace std; | ||
void func(int n) | ||
{ | ||
int i, j, k = n; | ||
for (i = 1; i < n+1; i++) { | ||
for (j = 1; j <2*n; j++) { | ||
if(i==n || i+j==n+1||j-i==n-1){ | ||
cout<<"*"<<"";} | ||
else{ | ||
cout << " ";} | ||
} | ||
cout << "\n"; | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
int n=0; | ||
cout<<"Enter Number Of Rows = "; | ||
cin>>n; | ||
func(n); | ||
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,16 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int main () { | ||
int n; | ||
cin>>n; | ||
for (int i = 0; i < n-1; i++) { | ||
for (int j = 0; j < (n-i-1); j++) cout<<" "; | ||
cout<<"*"; | ||
for (int j= 0; j < (2*i); j++) cout<<" "; | ||
if (i > 0) cout<<"*"; | ||
cout<<endl; | ||
} | ||
for (int i = 0; i < n; i++) cout<<"* "; | ||
return 0; | ||
} |
Oops, something went wrong.