Ребят , сколько сможете баллов
Задание 1
Напишите программу, которая находит среднее арифметическое всех чисел, записанных в файле в столбик, и выводит результат в другой файл.
Задание 2
Напишите программу, которая находит минимальное четное среди отрицательных и максимальное нечетное среди положительных чисел, записанных в файле, и выводит результат в виде написанных в столбик чисел в другой файл. Учтите, что таких чисел может вообще не быть.
1
var
mas:array[1..100] of integer;
i,n:integer;
en,out:text;
res:real;
qw,qwe:string;
begin
n:=0;
i:=1;
write('Введите полный путь к импортируемому файлу: ');readln(qw);
write('Введите полный путь к экспортируемому файлу: ');readln(qwe);
assign(en,qw+'.txt'); assign(out,qwe+'.txt');
reset(en); rewrite(out);
while not Eof(en) do
begin
readln(en,mas[i]);
n:=n+mas[i];
inc(i);
end;
res:=(n/(i-1));
write(out,res);
close(out);
close(en);
end.
Там во вторую тупо добавляешь:
max:=-100001;
min:=100001;
if (mas[i]<0) and (mas[i] mod 2 = 0) and (mas[i]<min) then min:=mas[i];
if (mas[i]>0) and (mas[i] mod 2 = 1) and (mas[i]>max) then max:=mas[i];
if (max=-100001)or(min=100001) then writeln(out,'ERROR: please, rewrite yor file')
else
begin
writeln(out,min);
writeln(out,max);
Тоже такие же задачи решал)) лол). Ты не из 604??)))
Завдання 3
//////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;
int main(){
for(int i = -5;i <= 5; i++){
if(i != -2 && sqrt((i*i)+7) - (20/(i+2)) == 0)
cout<<i<<endl;
}
return 0;
}
Завдання 4
//////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;
int main(){
cout.width(18);
cout.setf(ios::fixed,ios::floatfield);
cout.precision(3);
cout<<"X Y ";
for(double i = -4;i <= 4; i+=0.2){
if(i < 0){
cout.width(8);
cout<<i<<;
cout.width(8);
cout<<((i*i)-7)<<endl;
}
else if(i >= 0 && i <=2){
cout.width(8);
cout<<i<<;
cout.width(8);
cout<<sqrt(4-(i * i))<<endl;
}
else{
cout.width(8);
cout<<i<<;
cout.width(8);
if((int)i==3 && i < 3.2){
cout<<"NULL"<<endl;
continue;
}
cout<<(i/((i*i)-9))<<endl;
}
}
return 0;
}