For19. Дано целое число N (> 0). Найти произведение N! = 1*2*…*N (N-факториал). Чтобы избежать целочисленного переполнения, вычислять это произведение с помощью вещественной переменной и вывести его как вещественное число.
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | program For19; var Rez:Real; N, i :Integer; begin Write('Введите N: '); Readln(N); Rez:=1; For i:=1 to N do begin Rez:=Rez*i; end; Writeln(Rez); end. |
>
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include int main(void) { int n; printf("N:"); scanf ("%i", &n); float rez=1; int i; for (i =1; i<=n; ++i) rez *=(float)i; printf("%f \n ",rez); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <iostream> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int n; cout<<"N:"; cin>>n; float rez = 1; int i; for (i = 1; i <= n; ++i) rez *= (float)i; cout<< rez; } |
Здравствуйте
Досвидание
ку
c#?
нет блин #С
int n, x = 1;
n = int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
x *= i;
Console.WriteLine($"{x}");
}
#include
#include
using namespace std;
int main() {
int n, i, a=1;
cin >> n;
for (i = 1; i <= n; i++) {
a *= i;
}
cout <<"Factorial of "<<n<<" equals to: " << a;
}