For13. Дано целое число N (> 0). Найти значение выражения 1.1 — 1.2 + 1.3 — … (N слагаемых, знаки чередуются). Условный оператор не использовать.
>Решение Pascal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | program For13; var N, i,k :Integer; Rez:Real; begin Write('Введите N: '); Readln(N); rez:=0; k:=-1; For i:=1 to N do begin k:=k*(-1); Rez:=Rez+k*(1+0.1*i); end; Writeln(Rez); end. |
Решение C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <stdio.h> #include <math.h> int main(void) { int n; printf("N:"); scanf ("%i", &n); float rez=0; int i; for (i =1; i<=n; ++i) rez += pow(-1,i+1)*(1.0+(float)i/10); printf("rez = %f \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 <math.h> using namespace std; int main() { int n; cout << "n="; cin >> n; float rez=0; for (int i =1; i<=n; i++) rez += pow(-1,i+1)*(1.0+(float)i/10); cout << "Result=" << rez; return 0; } |
Решение C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | using System; namespace ConsoleApp { class Program { static void Main(string[] args) { Console.Write("n="); int n = Convert.ToInt32(Console.ReadLine()); double rez = 0; for (int i = 1; i <= n; i++) rez += Math.Pow(-1, i + 1) * (1.0 + (double)i / 10); Console.WriteLine("Result=" + rez); Console.ReadKey(); } } } |
>
Решение Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 rez=0; for (int i =1; i<=n; i++) rez += Math.pow(-1,i+1)*(1.0+(double)i/10); System.out.print("Result=" + rez); in.close(); } } |
#include
using namespace std;
int main(){
float a,s=0;
cin>>a;
for(float i=1;i<=a;i++)
s+=pow(-1,i+1)*(1.0+i/10);
cout<<s;
}
#include
using namespace std;
int main(){
float a,s=0;
cin>>a;
for(float i=1;i<=a;i++)
s+=pow(-1,i+1)*(1.0+i/10);
cout<<s;
}
program for1;
var
i,a,b : integer;
sum:real;
begin
readln(a);sum:=0;b:=1;
for i:=1 to a do begin sum:=sum+(1+i*0.1)*b; b:=(-1*b);end;
writeln (sum:2:3)
end.
WinFormApp_C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ZadachaAbramyan
{
public partial class For13 : Form
{
public For13()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Ffor f = new Ffor();
f.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
double n = double.Parse(textBox1.Text), j =0, j1=0 ;
for (double i=1.1; i<=(n/10)+1; i += 0.2)
{
j += i;
}
for (double i = 1.2; i <= (n / 10) + 1; i += 0.2)
{
j1 += -i;
}
j = j + j1;
j = Math.Round(j, 2);
listBox1.Items.Add(j);
}
}
}
Почему нет решений на РНР фиговая ИНФА
кто может объяснить на простом языке принцип работы?
x=int(input(‘=>’))
c=0
(rez)=0
for i in range(x):
rez -= pow(-1,i+1)*(1.0+float(i/10))
print(rez)