Professional Documents
Culture Documents
#include <cmath>
#include <string>
int fact = 1;
if (n < 2) {
fact = 1;
} else {
for (int i = 2; i <= n; i++) {
fact *= i;
}
}
cout << n << "! = " << fact;
}
// In day fibonaci:
void fibonacci() {
cout << "Nhap so luong so fibonacci can in: ";
int num;
cin >> num;
long arr[50];
arr[0] = 0;
arr[1] = 1;
if (n <= 2) {
cout << "Khong ton tai so nao!";
} else {
cout << "Cac so nguyen to nho hon " << n << ": ";
for (int i = 2; i < n; i++) {
bool isPrime = true;
for (int j = 2; j <= sqrt(i); j++) {
if (i % j == 0) {
isPrime = false;
}
}
if (isPrime == true) {
cout << i << " ";
}
}
}
}
char reverseStrNum[length];
int reverseIndex = length - 1;
for (int i = 0; i < length; i++) {
reverseStrNum[i] = strNum[reverseIndex];
reverseIndex--;
}
int sum = 0;
for (int i = 0; i < length; i++) {
sum += arr[i];
}
cout << "Tong cac chu so cua so " << n << ": ";
for (int i = 0; i < length - 1; i++) {
cout << arr[i] << "+";
}
cout << arr[length - 1] << " = " << sum;
}
int main()
{
tongCacChuSo();
return 0;
}