For11. Дано целое число N (> 0). Найти сумму N2 + (N + 1)2 + (N + 2)2 +…+ (2*N)2 (целое число).
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 | program For11; var N, Rez,i :Integer; begin Write('Введите N: '); Readln(N); rez:=0; For i:=0 to N do Rez:=Rez+sqr(N+i); Writeln(Rez); end. |
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <stdio.h> #include <math.h> int main(void) { int n; printf("N:"); scanf ("%i", &n); int i, rez=0; for (i =0; i<=n; ++i) rez +=pow(n+i,2); 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> #include <math.h> using namespace std; int main(){ int n; cout << "n="; cin >> n; float result = 0; for (int i =0; i<=n; i++) result += pow(n+i,2); cout << "Result=" << result; return 0; } |
Решение C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package abramyan; import java.util.Scanner; public class Abramyan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Price="); double c = in.nextDouble(); for (int i = 1; i <= 10; ++i) System.out.println(i + "kg = " + c*i); in.close(); } } |
>
Решение Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package abramyan; import java.util.Scanner; public class Abramyan { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("n="); int n = in.nextInt(); double result = 0; for (int i = 0; i <= n; i++) result += Math.pow(n + i, 2); System.out.print("Result=" + result); in.close(); } } |
C#
using System;
namespace Abramyan_For_2
{
class Program
{
static void Main(string[] args)
{
// For 11
Console.Write(«Введите целое число: «);
int N = int.Parse(Console.ReadLine());
double sum = 0;
for (double i = 0; i <= N; i++)
{
sum += Math.Pow((N + i), 2);
}
Console.WriteLine($"Сумма: {sum}");
Console.ReadKey();
}
}
}
JAVA:
import java.util.Scanner;
public class if1 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print(«n=»);
int n = in.nextInt();
double res = 0;
for (int i = 1; i <= n; i++)
res += Math.pow(n+i,2);
System.out.print("Sum=" + ((Math.pow(n,2))+res+Math.pow((2*n),2)));
in.close();
}
}
\\ В условии указано, что цикл начинается с квадрата "N" и заканчивается на (2*N)(в квадрате)
|| ||
N2 + (N + 1)2 + (N + 2)2 +…+ (2*N)2 (целое число).
Python:
def for11():
num = int(input(‘Введите целое число: ‘))
amountAll = 0
if num>0:
amount1 = num**2
amount2 = (2*num)**2
for i in range(1,num+1):
amount = (num+i)**2
amountAll+= amount
print(amountAll + amount1 + amount2)
else:
print(‘Число должно быть > 0’)
for11()