File tree Expand file tree Collapse file tree 2 files changed +143
-0
lines changed
Expand file tree Collapse file tree 2 files changed +143
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * @author: Karthick < karthikn2099@gmail.com >
3+ * @github: https://github.com/karthikn2098
4+ * @date: 15/01/2018
5+ */
6+
7+ #include < iostream>
8+ using namespace std ;
9+
10+ void fizzBuzz1 (int N) {
11+
12+ for ( int i = 1 ; i <= N ; i++ ) {
13+
14+ if ( (i % 3 == 0 ) && (i % 5 == 0 ) ) {
15+ cout << " FizzBuzz " ;
16+ }
17+ else if ( i % 3 == 0 ) {
18+ cout << " Fizz " ;
19+ }
20+ else if ( i % 5 == 0 ) {
21+ cout << " Buzz " ;
22+ }
23+ else {
24+ cout << i << " " ;
25+ }
26+
27+ }
28+ }
29+
30+ void fizzBuzz2 (int N) {
31+
32+ for ( int i = 1 ; i <= N ; i++ ) {
33+
34+ string str = " " ;
35+
36+ if (i % 3 == 0 ) str += " Fizz" ;
37+
38+ if (i % 5 == 0 ) str += " Buzz" ;
39+
40+ if (str == " " ) {
41+ cout << i << " " ;
42+ }
43+ else {
44+ cout << str << " " ;
45+ }
46+
47+ }
48+
49+ }
50+
51+ int main (void ) {
52+
53+ int N;
54+
55+ cout << " Enter N: " ;
56+ cin >> N;
57+
58+ fizzBuzz1 (N);
59+ cout << endl << endl;
60+
61+ fizzBuzz2 (N);
62+ cout << endl << endl;
63+
64+ return 0 ;
65+ }
66+
67+ /* *
68+ ---------------------
69+ Sample Input/Output
70+ ---------------------
71+
72+ Enter N: 25
73+ 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
74+
75+ 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
76+
77+ */
Original file line number Diff line number Diff line change 1+ /* *
2+ * @author: Karthick < karthikn2099@gmail.com >
3+ * @github: https://github.com/karthikn2098
4+ * @date: 15/01/2018
5+ */
6+
7+ #include < iostream>
8+ #include < string>
9+ using namespace std ;
10+
11+ // function to reverse the string.
12+ string reverse_string ( string str ) {
13+
14+ int i = 0 , j = str.length () - 1 ;
15+
16+ while (i <= j) {
17+ swap (str[i++] , str[j--]);
18+ }
19+
20+ return str;
21+ }
22+
23+ // function that checks the string is palindrome or not.
24+ bool checkPalindrome ( string str ) {
25+
26+ int i = 0 , j = str.length () - 1 ;
27+
28+ while ( i <= j ) {
29+ if ( str[i++] != str[j--] ) {
30+ return false ;
31+ }
32+ }
33+
34+ return true ;
35+ }
36+
37+
38+ int main (void ) {
39+
40+ cout << " Reverse of abcd: " << reverse_string (" abcd" );
41+
42+ cout << " \n\n Reverse of abcde: " << reverse_string (" abcde" );
43+
44+ cout << endl;
45+
46+ if ( checkPalindrome (" amma" ) ) {
47+ cout << " \n Palindrome\n " ;
48+ }
49+ else {
50+ cout << " \n Not a palindrome\n " ;
51+ }
52+
53+
54+ return 0 ;
55+ }
56+
57+ /* *
58+ Output:
59+
60+ Reverse of abcd: dcba
61+
62+ Reverse of abcde: edcba
63+
64+ Palindrome
65+
66+ */
You can’t perform that action at this time.
0 commit comments