For9. Даны два целых числа A и B (A < B). Найти сумму квадратов всех целых чисел от A до B включительно.
Решение Python
1 2 3 4 5 6 7 8 9 | # Input integers A and B A = int(input("Enter the value of A: ")) B = int(input("Enter the value of B: ")) # Calculate the sum of squares of integers from A to B total_sum_of_squares = sum(num ** 2 for num in range(A, B + 1)) # Output the sum of squares print(f"The sum of squares of integers from {A} to {B} inclusive is: {total_sum_of_squares}") |
>
Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 | program For9; var A,B,Rez, i:Integer; begin Write('Введите A: '); Readln(A); Write('Введите B: '); Readln(B); rez:=0; For i:=A to B do Rez:=Rez+sqr(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=0; for (i =a; i<=b; ++i) rez +=i*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 | #include <iostream> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int a, b; cout <<"a:"; cin >> a; cout << "b:"; cin >> b; int i, rez = 0; for (i = a; i <= b; ++i) rez += i * i; cout << "Rez: " << rez; } |
#include
using namespace std;
int main(){
int a,b;
cout <>a;
cout <> b;
int i, rez=0;
for (i =a; i<=b; ++i)
rez +=i*i;
cout <<"Rez: "<<rez;
}
Java
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(«a: «);
double a = scanner.nextDouble();
System.out.print(«b: «);
double b = scanner.nextDouble();
double sum = 1;
for (double i = a; i <= b; i++) {
sum = sum * Math.pow(i, 2);
}
System.out.println("Kv sum: " + sum);
}
#Python
counter = 0
a = int(input(«Type a: «))
b = int(input(«Type b: «))
if a < b:
for i in range(a, b + 1):
counter += i ** 2
print(counter)
Спасибо большое вам
kotlin;
fun main() {
val A = 1
val B = 5
var sumSqr = 0
for(i in A..B){
sumSqr += i*i
println(sumSqr)
}
}
System.out.println(«A:»);
int a = sc.nextInt();
System.out.println(«B:»);
int b = sc.nextInt();
int sum = 1;
for (int i = a; i<=b; i++){
sum += i*i;
}
System.out.println(sum);
можно на js
пж
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 sumOfSquares = 0;
for (int i = a; i <= b; i++)
sumOfSquares += i * i;
Console.WriteLine("SumOfSquares= " + sumOfSquares);
}
}