Created
May 5, 2016 02:57
-
-
Save batmantec/0d0f83d1b8437a6ee39cb1c253884841 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <string> | |
using namespace std; | |
void triangle(int t){ | |
int i, x; | |
for (i = 0; i <= t; i++){ | |
cout << endl; | |
for (x = 0; x < i; x++){ | |
cout << "T"; | |
} | |
} | |
cout << endl; | |
for (i = 0; i < t; i++){ | |
for (x = 0; x < t-i-1; x++){ | |
cout << "T"; | |
} | |
cout << endl; | |
} | |
} | |
int exponential(long int c, long int d){ | |
long int i, result; | |
result = c; | |
for (i = 1; i < d; i++) { | |
result = result * c; | |
} | |
return result; | |
} | |
int fib (int x){ | |
int y; | |
if (x>=2){ | |
y=fib(x-1) + fib (x-2); | |
return y; | |
} | |
else | |
if (x==1) | |
return 1; | |
else | |
return 0; | |
} | |
void checkPal(string word){ | |
int i; | |
for(i=0; i<(word.size()/2); i++){ | |
if(word[i]!=(word[word.size()-1-i])) | |
break; | |
} | |
if(i==(word.size()/2)) | |
cout << word <<" is a palindrome"<<endl; | |
else | |
cout << word <<" is NOT a palindrome"<<endl; | |
} | |
int main (){ | |
int menu; | |
cout << "Here is the compilation of the exam programs." << endl << endl; | |
cout << "1. Creat a triangle with T's " << endl << endl; | |
cout << "2. Elevate to a power a number" << endl << endl; | |
cout << "3. Fibonacci " << endl << endl; | |
cout << "4. Palindrome" << endl << endl; | |
cout << "Please type the number of the option:"; | |
cin >> menu; | |
switch (menu) { | |
case 1: | |
int t; | |
cout << "Type the size of the triange: "; | |
cin >> t; | |
triangle(t); | |
break; | |
case 2: | |
int a, b; | |
long int to; | |
cout << "Type number you want to raise: "; | |
cin >> a; | |
cout << "Type the exponential number: "; | |
cin >> b; | |
to = exponential(a,b); | |
cout << "Your result is: " << to << endl; | |
break; | |
case 3: | |
int x, ans; | |
cout << "This program calculates the Fibonacci number that you want."<<endl; | |
cout << "Give me a number: "; | |
cin >> x; | |
ans = fib (x); | |
cout << "The Fibonacci number is: "<<ans<<endl; | |
break; | |
case 4: | |
string word; | |
cout << "What word you want to check (please enter all in lower case): "; | |
cin >> word; | |
checkPal(word); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment