1. Prím
#include <iostream>
using namespace std;
int main()
{
bool prim = true;
int szam;
cin >> szam;
for(int oszto = 2; oszto <= szam/2; oszto++){
if (szam % oszto == 0){
prim = false;
}
}
if (prim) {
cout << "a szam prim";
} else {
cout << "a szam nem prim";
}
return 0;
}
2. Pallindróm
#include <iostream>
using namespace std;
int main()
{
int szam, ujszam = 0, temp;
cin >> szam;
temp = szam;
while (temp > 0) {
int szamjegy = temp % 10;
temp = temp / 10;
ujszam = ujszam * 10 + szamjegy;
}
if (ujszam == szam) {
cout << "pallindrom";
} else {
cout << "nem pallindrom";
}
return 0;
}
3. Fibbonacci
#include <iostream>
using namespace std;
int main()
{
int prev=1, next=1, F=1, n;
cin >> n;
for(int i = 3; i<= n; i++)
{
F = prev + next;
prev = next;
next = F;
}
cout << F;
return 0;
}
4. Lnko/Lkkt
#include <iostream>
using namespace std;
int main()
{
int a, b, lkkt;
cin >> a >> b;
lkkt = a * b;
while(a != b){
if (a>b){
a -= b;
} else {
b -= a;
}
}
cout << "lnko " << a << endl;
cout << "lkkt " << lkkt / a;
return 0;
}