uj csoport feladatok

This commit is contained in:
kaoplo 2022-12-13 13:24:06 +01:00
parent b2dfcfd075
commit 9596abb41b
6 changed files with 96 additions and 0 deletions

BIN
quito/7.1 Executable file

Binary file not shown.

56
quito/7.1.cpp Normal file
View file

@ -0,0 +1,56 @@
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// 7.1, 7.2, 7.3 feladatok megoldasai
bool prim(int n) {
if (n == 1) return false;
if (n == 2) return false;
for (int i = 2; i < n; i++) {
if (n%i==0){
return false;
}
}
return true;
}
int convert(string a) {
int out = 0;
int counter = 1;
for (int i = a.size() - 1; i >= 0; i--) {
if (a[i] == '1') {
out += counter;
}
counter = counter *2;
}
return out;
}
int lnko(int n, int k) {
vector<int>osztok1;
vector<int>osztok2;
for (int i = 1; i <= n; i++) {
if (n%i==0) osztok1.push_back(i);
}
for (int i = 1; i <= k; i++) {
if (k%i==0) osztok2.push_back(i);
}
int out=1;
for (int i = 0; i < osztok1.size(); i++) {
for (int j = 0; j < osztok2.size(); j++) {
if ((osztok1[i] == osztok2[j]) && (osztok1[i] > out)) {
out = osztok1[i];
}
}
}
return out;
}
int main() {
cout<<prim(13)<<' '<<prim(2)<<' '<<prim(6);
cout<<endl<<convert("0101101");
cout<<endl<<lnko(38, 14)<<' '<<lnko(16,12)<<' '<<lnko(432,527);
cout<<endl<<lnko(284,1283);
}

BIN
quito/7.5 Executable file

Binary file not shown.

24
quito/7.5.cpp Normal file
View file

@ -0,0 +1,24 @@
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
// 7.5, 7.6 feladatok megoldasai
long long factorial (long long n) {
if (n==0) return 1;
return n * factorial(n-1);
}
int stringToInt (string n) {
if (n == "") return 0;
return (stringToInt(n.substr(0, n.size() -1)) * 10) + n.back() - '0' ;
}
int maximum(vector<int> v) {
}
int main () {
cout<<factorial(13);
cout<<endl<<stringToInt("7839");
}

BIN
quito/8.1 Executable file

Binary file not shown.

16
quito/8.1.cpp Normal file
View file

@ -0,0 +1,16 @@
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int hatvany (int n, int k) {
if (k == 0) return 1;
return n * hatvany(n, k-1);
}
int main () {
cout<<hatvany(2,12)<< ' '<<hatvany(5,6)<< ' ' << hatvany(1,3);
}