chore: Lab07

This commit is contained in:
Fándly Gergő 2020-05-01 17:58:05 +03:00
parent 7adb051d16
commit 4a6331088a
3 changed files with 69 additions and 0 deletions

22
lab07/01.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int fib(int n){
if(n <= 1){
return n;
}
return fib(n-1) + fib(n-2);
}
int main(){
int n;
cout<<"N = ";
cin>>n;
for(int i=0; i<n; i++){
cout<<fib(i)<<", ";
}
cout<<"\b\b "<<endl;
return 0;
}

22
lab07/02.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int convert(int number, int base){
if(number == 0 || base == 10){
return number;
}
return (number%base) + 10 * convert(number / base, base);
}
int main(){
int n, base;
cout<<"Number: ";
cin>>n;
cout<<"Target base: ";
cin>>base;
cout<<"Result: "<<convert(n, base)<<endl;
return 0;
}

25
lab07/03.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(string str){
if(!str.size()){
return true;
}
if(str.front() != str.back()){
return false;
}
return isPalindrome(str.substr(1, str.size() - 2));
}
int main(){
string str;
cout<<"Enter a word: ";
cin>>str;
cout<<"The word is "<<(isPalindrome(str) ? "" : "not ")<<"palindrome."<<endl;
return 0;
}