1.
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
long long a[20], i, sum = 0, sum1 = 0;
for(i = 0; i < 20; i++)
{
cin >> a[i];
if(a[i] < 0)
{
sum += a[i];
sum1++;
}
}
for(i = 0; i < 20; i++)
cout << a[i] << " ";
cout << endl;
cout << sum << " " << sum1 << " " << sum / sum1 << endl;
return 0;
}
2.
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
long long b[6][4], i, j;
for(i = 0; i < 6; i++)
{
for(j = 0; j < 4; j++)
{
b[i][j] = rand() % 100;
if(b[i][j] > 9 && b[i][j] < 100)
b[i][j] = 10;
cout << b[i][j] << " ";
}
cout << endl;
}
return 0;
}
Объяснение:
1.
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
long long b[31], i;
for(i = 0; i < 30; i++)
{
b[i] = rand();
cout << b[i] << " ";
}
for(i = 0; i < 30; i++)
if(b[i] > 0)
cout << i << " " << b[i] << endl;
return 0;
}
2.
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
long long b[5][5], i, j, sum = 1;
for(i = 0; i < 5; i++)
for(j = 0; j < 5; j++)
{
cin >> b[i][j];
if(i == j)
sum *= b[i][i];
}
for(i = 0; i < 5; i++)
{
for(j = 0; j < 5; j++)
cout << b[i][j] << " ";
cout << endl;
}
cout << sum << endl;;
return 0;
}
Объяснение:
var f: text; { Если не будет работать, то написать вместо "text" "file of longint" или еще что-нибудь другое.}
x, y: longint;
i: byte;
begin
y := 0;
assign(f, 'a4');
reset(f);
for i := 1 to 28 do
begin
read(f, x);
y := y + x;
end;
writeln(y / 28);
close(f);
end.