In this Quiz we had to do two tasks.
In the first one we had to create a program which calculates the Fibbonaci number of a value that we give to the computer.
So the codes for the first task would look like this:
#include <iostream> using namespace std; long n; long fibonacci (long n){ long a=0, b=1, c=0; if(n==1){ c=1; } for (int i=0; i<n-1; i++) { c=a+b; a=b; b=c; } return c; } int main(){ cout<<"Please introduce a possitive number: "; cin>>n; if (n>=0) { cout<<"The result is: "<<fibonacci(n); } else { cout<<"Invalid"; } return 0; }
And for the second task we had to write the codes which can identify a Palindrom number, for example; 11.
Here are the codes for the second task:
#include <iostream> #include <string> using namespace std; bool isPalindrome(string x){ if(x== string(x.rbegin(), x.rend())) return true; else return false; } int main(){ string a; cout << "Write a Palindrome " << endl; cin>>a; bool y= isPalindrome(a); if (y == true) { cout << "¡That's correct!" << endl; } else { cout << "¡Sorry, that's incorrect!" << endl; } return 0; }
I will also leave the codes in my Github Account, just clic here!
And here is the execution of both programs.
Keep practicing and stay cool.
-The Admin.
Quiz #7 by esaupreciado is licensed under a Creative Commons Attribution 4.0 International License.