Задача 1:
#include <iostream>
using namespace std;
int main()
{
int a{}, b{};
cout << "a = ";
cin >> a;
cout << endl << "b = ";
cin >> b;
if (a < b) a *= 2, b *= 3;
else b *= 2, a *= 3;
cout << endl << endl << "a = " << a << endl << "b = " << b;
return 0;
}
Задача 2:
#include <iostream>
using namespace std;
int main()
{
int a{};
cout << "a = ";
cin >> a;
if (!(a % 2)) cout << endl << a * a; //if (!(a % 2)) = теж саме, що й if (a % 2 == 0)
else cout << endl << a * a * a;
return 0;
}
Задача 3:
#include <iostream>
using namespace std;
int main()
{
int sum{};
for (int i = 11; i < 100; i += 2) sum += i;
cout << sum;
return 0;
}
Задача 4:
#include <iostream>
using namespace std;
int main()
{
for (int i = 144; i < 1000; i += 48) cout << i << " ";
return 0;
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace Prog
{
class Program
{
static void Main(string[] args)
{
List<double> array = new List<double>() { 7, 25, 4.5, 0, 17, 61, -10, 0, 1, -4, 22 };
// TASK 5
int positive, negative, zero;
var tmp = array.FindAll(x => x > 0);
positive = tmp.Count;
tmp = array.FindAll(x => x == 0);
zero = tmp.Count;
negative = array.Count - zero - positive;
Console.WriteLine($"Кол-во полож. элементов: {positive}\n\rКол-во нулевых элементов: {zero}\n\rКол-во отриц. элементов: {negative}");
// TASK 6
double prv = 1;
for (int i = 0; i < array.Count; ++i)
{
if (array[i] != 0)
{
prv *= array[i];
}
}
Console.WriteLine($"Произведение ненулевых элементов равно: {prv}");
Console.ReadKey();
}
}
}
Объяснение:
const n=10;
var a:array[1..n] of integer;
k,i:integer;
begin
writeln('vvedite massiv=');
for i := 1 to n do
readln(a[i]);
k:=0;
for i := 1 to n do
if a[i]>0 then inc(k);
writeln ('k=',k);
readln;
end.
1)
const n=10;
var a:array[1..n] of integer;
s,p,i:integer;
begin
writeln('vvedite massiv=');
for i := 1 to n do
readln(a[i]);
s:=0;
p:=1;
for i := 1 to n do
if (a[i] mod 2=1) and (a[i] mod 3=0) then begin
s:=s+a[i];
p:=p*a[i];
end;
writeln('s=',s, ' p=',p);
readln;
end.