Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* factorial in c++ * fibonacci recursion * c++ code for day14 * C++ solution for day15 added * day1 FizzBuzz Code in C++ * C++ code for day2
- Loading branch information
1 parent
bcf5557
commit 0ce465a
Showing
2 changed files
with
143 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,77 @@ | ||
/** | ||
* @author: Karthick < karthikn2099@gmail.com > | ||
* @github: https://github.com/karthikn2098 | ||
* @date: 15/01/2018 | ||
*/ | ||
|
||
#include <iostream> | ||
using namespace std; | ||
|
||
void fizzBuzz1(int N) { | ||
|
||
for( int i = 1 ; i <= N ; i++ ) { | ||
|
||
if( (i % 3 == 0) && (i % 5 == 0) ) { | ||
cout << "FizzBuzz "; | ||
} | ||
else if( i % 3 == 0 ) { | ||
cout << "Fizz "; | ||
} | ||
else if( i % 5 == 0 ) { | ||
cout << "Buzz "; | ||
} | ||
else { | ||
cout << i << " "; | ||
} | ||
|
||
} | ||
} | ||
|
||
void fizzBuzz2(int N) { | ||
|
||
for( int i = 1 ; i <= N ; i++ ) { | ||
|
||
string str = ""; | ||
|
||
if(i % 3 == 0) str += "Fizz"; | ||
|
||
if(i % 5 == 0) str += "Buzz"; | ||
|
||
if(str == "") { | ||
cout << i << " "; | ||
} | ||
else { | ||
cout << str << " "; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
int main(void) { | ||
|
||
int N; | ||
|
||
cout << "Enter N: "; | ||
cin >> N; | ||
|
||
fizzBuzz1(N); | ||
cout << endl << endl; | ||
|
||
fizzBuzz2(N); | ||
cout << endl << endl; | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
--------------------- | ||
Sample Input/Output | ||
--------------------- | ||
Enter N: 25 | ||
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz | ||
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz | ||
*/ |
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,66 @@ | ||
/** | ||
* @author: Karthick < karthikn2099@gmail.com > | ||
* @github: https://github.com/karthikn2098 | ||
* @date: 15/01/2018 | ||
*/ | ||
|
||
#include <iostream> | ||
#include <string> | ||
using namespace std; | ||
|
||
//function to reverse the string. | ||
string reverse_string( string str ) { | ||
|
||
int i = 0 , j = str.length() - 1; | ||
|
||
while(i <= j) { | ||
swap(str[i++] , str[j--]); | ||
} | ||
|
||
return str; | ||
} | ||
|
||
//function that checks the string is palindrome or not. | ||
bool checkPalindrome( string str ) { | ||
|
||
int i = 0 , j = str.length() - 1; | ||
|
||
while( i <= j ) { | ||
if( str[i++] != str[j--] ) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
int main(void) { | ||
|
||
cout << "Reverse of abcd: " << reverse_string("abcd"); | ||
|
||
cout << "\n\nReverse of abcde: " << reverse_string("abcde"); | ||
|
||
cout << endl; | ||
|
||
if( checkPalindrome("amma") ) { | ||
cout << "\nPalindrome\n"; | ||
} | ||
else { | ||
cout << "\nNot a palindrome\n"; | ||
} | ||
|
||
|
||
return 0; | ||
} | ||
|
||
/** | ||
Output: | ||
Reverse of abcd: dcba | ||
Reverse of abcde: edcba | ||
Palindrome | ||
*/ |