For8. Даны два целых числа A и B (A < B). Найти произведение всех целых чисел от A до B включительно.
Решение Python
1 2 3 4 5 6 7 8 9 10 11 | # Input integers A and B A = int(input("Enter the value of A: ")) B = int(input("Enter the value of B: ")) # Calculate the product of integers from A to B total_product = 1 for num in range(A, B + 1): total_product *= num # Output the product print(f"The product of integers from {A} to {B} inclusive is: {total_product}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 | program For8; var A,B,Rez, i:Integer; begin Write('Введите A: '); Readln(A); Write('Введите B: '); Readln(B); rez:=1; For i:=A to B do Rez:=Rez*i; Writeln(Rez); end. |
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include int main(void) { int a,b; printf("A:"); scanf ("%i", &a); printf("B:"); scanf ("%i", &b); int i, rez=1; for (i =a; i<=b; ++i) rez *=i; printf("rez = %i \n ",rez); return 0; } |
Решение C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> #include <cmath> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int a, b, c=1; cout << "A:"; cin >> a; cout << "b:"; cin >> b; for (int i = a; i <= b; i++) { c *= i; } cout << c; } |
А можно C#??????)))))
+
using System;
class Lab
{
static void Main()
{
Console.Write(«a=»);
int a = Convert.ToInt32(Console.ReadLine());
Console.Write(«b=»);
int b = Convert.ToInt32(Console.ReadLine());
int prod = 1;
for (int i = a; i <= b; i++)
prod *= i;
Console.WriteLine("Prod=" + prod);
}
}
классные задачи
//kotlin:
fun main() {
val A = 1
val B = 5
var product = 1 //product должен быть ровно 1 изначально, а то компилятор нафиг вас пошлет, логично, посмотрите по алгоритму действий
for(i in A..B){
product *= i //Это значит product = product * i, то есть product ровно уже имеющее число * i — каждый раз по циклу
//если а=1 и b=5, то получится в итоге 1*1*2*3*4*5=120
//если а=5 и b=10, то получится в итоге 1*5*6*7*8*9*10=151200 (не забудьте у нас product = 1 изначально, главное понять)
println(product)
}
}
//*product — значит произведение
C++ (существует обратный способ нахождения фрактала):
#include
int main()
{
setlocale(LC_ALL, «Rus»);
int a, b;
unsigned long s = 1;
std::cout < a): «;
std::cin >> b >> a;
for (int i = b; i >= a ; i—)
s *= i;
std::cout << "Произведение чисел от B до A = " << s << std::endl;
return 0;
}
можно на js пж )
+
JavaScript
// let a = +prompt(«son kiriting»)
// let b = +prompt(«son kiriting»)
// let c = 1
// for(i=a;i<=b;i++){
// c*=i
// console.log(c)
// }
using System;
class Lab
{
static void Main()
{
Console.Write(«a=»);
int a = Convert.ToInt32(Console.ReadLine());
Console.Write(«b=»);
int b = Convert.ToInt32(Console.ReadLine());
int prod = 1;
for (int i = a; i <= b; i++)
prod *= i;
Console.WriteLine("Prod=" + prod);
}
}