Program enot;
Var a: array [1..22] of integer;
i,h,n,k,c:integer;
l:real;
begin
for i:=1 to 22 do
a[i]:=random(51)-25;
for i:=1 to 22 do
begin
if a[i]>0 then begin c:=c+a[i];
k:=k+1;
end;
l:=c/k;
n:=0;
h:=0;
if a[i]<0 then h:=h+1;
if a[i]=0 then n:=n + 1;
end;
writeln(a[i],'среднее арифметическое= ',l:2:2,'; количество отрицательных = ', h,'; количество равных нулю = ',n);
<span>end.
Вот и вторая задача:
Program enot;
Var a: array [1..4,1..4] of integer;
i,j,s,p,h:integer;
o:real;
begin
for i:= 1 to 4 do
for j:= 1 to 4 do
a[i,j]:= random(25)-12;
p:=1;
for i:= 1 to 4 do
begin
s:=s+a[i,3];
p:=p*a[i,i];
end;
writeln('summa= ',s,'; произведение= ',p);
for i:= 1 to 4 do
for j:= 1 to 4 do
begin
h:=h+a[i,j];
o:=h/16;
end;
writeln('среднее арифметическое= ',o);
end.<span>
</span></span>
1)
var a,b,c:real;
begin
write('Введите три стороны треугольника: ');
readln(a,b,c);
if((a < b+c) and (b < a+c) and (c < a+b)) then write('Периметр треугольника: ',(a+b+c):9:3)
else write('Треугольник с данным сторонами не существует');
end.
2)
var a,b:real;
begin
write('Введите два числа: ');
readln(a,b);
writeln('Сумма данных чисел: ',(a+b):9:3);
write('Произведение данных чисел: ',(a*b):9:3);
end.
#include "stdafx.h"
#include <iostream>
#include <cmath>
struct coord
{
double x;
double y;
};
using namespace std;
void TriangleExist(coord a, coord b, coord c)
{
double modAB = sqrt(pow((a.x-b.x),2)+pow((a.y-b.y),2));
double modAC = sqrt(pow((a.x-c.x),2)+pow((a.y-c.y),2));
double modBC = sqrt(pow((b.x-c.x),2)+pow((b.y-c.y),2));
if (modAB+modAC <= modBC)
cout << "Do not exist" << endl;
else if (modAC + modBC <= modAB)
cout << "Do not exist" << endl;
else if (modAB+modBC <= modAC)
cout << "Do not exist" << endl;
else
cout << "Exist" << endl;
}
int main()
{
coord A, B, C;
cin >> A.x >> A.y;
cin >> B.x >> B.y;
cin >> C.x >> C.y;
TriangleExist(A, B, C);
system("pause");
exit(0);
return 0;
}
Еще способ с чистым мейном.
#include <iostream>
#include <conio.h>
#include <cmath> //математическая библия, ну очень облегчает задачу :)))
using namespace std;
void main(void)
{
double Ax, Ay, Bx, By, Cx, Cy;
cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy;
double modAB = sqrt(pow((Ax-Bx),2)+pow((Ay-By),2));
double modAC = sqrt(pow((Ax-Cx),2)+pow((Ay-Cy),2));
double modBC = sqrt(pow((Bx-Cx),2)+pow((By-Cy),2));
if (modAB+modAC <= modBC)
cout << "Do not exist" << endl;
else if (modAC + modBC <= modAB)
cout << "Do not exist" << endl;
else if (modAB+modBC <= modAC)
cout << "Do not exist" << endl;
else
cout << "Exist" << endl;
_getch();
return;
}