chore: Lab07
This commit is contained in:
		
							
								
								
									
										22
									
								
								lab07/01.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								lab07/01.cpp
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										22
									
								
								lab07/02.cpp
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										25
									
								
								lab07/03.cpp
									
									
									
									
									
										Normal 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;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user