forked from harshilp24/Hacktoberfest_2021
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rishabh Balaiwar
committed
Oct 2, 2020
1 parent
5bbb172
commit 263596e
Showing
9 changed files
with
233 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,24 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
void leapYear(int year) | ||
{ | ||
if((year % 4 == 0 && year % 100 != 0 ) || (year % 400 == 0)) | ||
{ | ||
cout<<"Yes it's a leap year"<<endl; | ||
} | ||
else | ||
{ | ||
cout<<"No it's not a leap year"<<endl; | ||
} | ||
|
||
} | ||
int main() | ||
{ | ||
int year; | ||
cin>>year; | ||
{ | ||
leapYear(year); | ||
} | ||
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,33 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
using namespace std; | ||
|
||
bool isPalRec(char input[],int s,int e) | ||
{ | ||
if(s==e) | ||
return true; | ||
if(input[s]!=input[e]) | ||
return false; | ||
if(s<e+1) | ||
return isPalRec(input,s+1,e-1); | ||
return true; | ||
} | ||
bool checkPalindrome(char input[]) { | ||
int n=strlen(input); | ||
if(n==0) | ||
return true; | ||
return isPalRec(input,0,n-1); | ||
} | ||
int main() { | ||
char input[50]; | ||
cin >> input; | ||
|
||
if(checkPalindrome(input)) { | ||
cout << "true" << endl; | ||
} | ||
else { | ||
cout << "false" << 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,22 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int n; | ||
cin >> n; | ||
cout << countZeros(n) << endl; | ||
} | ||
|
||
int countZeros(int n) { | ||
// Write your code here | ||
if(n==0) | ||
return 1; | ||
if(n<10) | ||
return 0; | ||
else if(n%10==0) | ||
return 1+countZeros(n/10); | ||
return countZeros(n/10); | ||
} | ||
|
||
|
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,41 @@ | ||
#include<iostream> | ||
using namespace std; | ||
|
||
int firstIndex(int input[], int size, int x) { | ||
if(size==1){ | ||
if(input[0]==x) | ||
return 0; | ||
else | ||
return -1; | ||
} | ||
|
||
if(input[0]==x) | ||
return 0; | ||
else{ | ||
int index=firstIndex(input+1,size-1,x); | ||
if(index != -1) | ||
return index+1; | ||
else | ||
return -1; | ||
} | ||
|
||
} | ||
int main(){ | ||
int n; | ||
cin >> n; | ||
|
||
int *input = new int[n]; | ||
|
||
for(int i = 0; i < n; i++) { | ||
cin >> input[i]; | ||
} | ||
|
||
int x; | ||
|
||
cin >> x; | ||
|
||
cout << firstIndex(input, n, x) << 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,21 @@ | ||
#include <iostream> | ||
#include <math.h> | ||
#include <iomanip> | ||
using namespace std; | ||
|
||
int main() { | ||
int k; | ||
cin >> k; | ||
cout << fixed << setprecision(5); | ||
cout << geometricSum(k) << endl; | ||
} | ||
|
||
double geometricSum(int k) { | ||
// Write your code here | ||
if(k==0) | ||
return 1; | ||
double ans = 1 / (double)pow(2, k) + geometricSum(k - 1); | ||
return ans; | ||
} | ||
|
||
|
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,17 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int multiplyNumbers(int m, int n) { | ||
// Write your code here | ||
if(m==0) | ||
{ | ||
return 0; | ||
} | ||
int result=(m*n); | ||
return result; | ||
} | ||
int main() { | ||
int m, n; | ||
cin >> m >> n; | ||
cout << multiplyNumbers(m, 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,23 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
void removeX(char input[]) { | ||
// Write your code here | ||
if(input[0]=='\0') | ||
return; | ||
if(input[0]=='x'){ | ||
int i=1; | ||
for(;input[i]!='\0';i++) | ||
input[i-1]=input[i]; | ||
input[i-1]=input[i]; | ||
removeX(input); | ||
} | ||
removeX(input+1); | ||
} | ||
int main() { | ||
char input[100]; | ||
cin.getline(input, 100); | ||
removeX(input); | ||
cout << input << 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,30 @@ | ||
#include <iostream> | ||
#include <cstring> | ||
using namespace std; | ||
|
||
void replacePi(char input[]) { | ||
// Write your code here | ||
if(input[0]=='\0') | ||
return; | ||
if(input[0]=='p' && input[1]=='i') | ||
{ | ||
input[0]='3'; | ||
input[1]='.'; | ||
|
||
int size=strlen(input); | ||
for(int i=size+2;i>1;i--) | ||
{ | ||
input[i]=input[i-2]; | ||
} | ||
input[2]='1'; | ||
input[3]='4'; | ||
} | ||
replacePi(input+1); | ||
} | ||
int main() { | ||
char input[10000]; | ||
cin.getline(input, 10000); | ||
replacePi(input); | ||
cout << input << 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,22 @@ | ||
#include <iostream> | ||
#include<cmath> | ||
#include<cstring> | ||
using namespace std; | ||
|
||
int stringToNumber(char input[]) { | ||
// Write your code her | ||
if (input[0]=='\0') | ||
return 0; | ||
int ans=stringToNumber(input+1); | ||
|
||
int size=strlen(input); | ||
int d=(input[0]-48)*pow(10,size-1); | ||
return ans+d; | ||
|
||
} | ||
|
||
int main() { | ||
char input[50]; | ||
cin >> input; | ||
cout << stringToNumber(input) << endl; | ||
} |