#include <iostream>
#include <ctime>
int main()
{
using namespace std;
setlocale(LC_ALL, "ru");
srand(time(NULL));
int size;
int mult = 1;
cout << "Введите размер массива: " << endl;
cin >> size;
int *arr = new int[size];
cout << "Массив: " << endl;
for (int i = 0; i < size; i++)
{
arr[i] = rand() % 50 - 25;
cout << arr[i] << '\t';
if (i & 1 && arr[i] != 0)
mult *= arr[i];
}
cout << "\nРезультат: " << mult;
delete[] arr;
return 0;
}
n, counter, spisok, new_spisok = int(input()), 0, [], []
while counter != n:
spisok.append(int(input()))
counter += 1
c1, c2 = int(input()), int(input())
for i in spisok:
if c1 <= i <= c2:
new_spisok.append(i)
print(new_spisok, len(new_spisok))
Объяснение:
1) хз зачем там цикл while, но раз в условии написано, то сделал через него;
2) скорее всего работать нужно со списками, а не массивами, так как append - метод списка;
3) если нужно, могу объяснить каждую строку;
4) формат вывода массива не указан, поэтому вывод обычного массива с его длиной через запятую;
5) нижние слеши это пробелы типа)
Объяснение:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace CSLear
{
partial class Program
{
static void Main(string[] args)
{
Student Лёха = new Student("Свотин", "Алексей", 21, "ПИ 2-3", new int[5] { 4, 5, 3, 5, 3, });
Лёха.GetInfo();
Console.WriteLine($"Отдельно выведенные оценки Лёхи: {Лёха.AverageMark}");
Console.ReadKey();
}
}
class Student
{
public string Surname { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Group { get; set; }
public int[] Marks { get; set; }
public double AverageMark => Marks.Average();
public Student(string Surname, string Name, int Age, string Group, int[] MarkList)
{
this.Surname = Surname;
this.Name = Name;
this.Age = Age;
this.Group = Group;
Marks = MarkList;
}
public void GetInfo()
{
Console.WriteLine($"Студент: {Surname} {Name}\nГруппа: {Group}\nСредний : {AverageMark}");
}
}
}
Объяснение:
Да, в VS 2019 можно использовать кириллицу для наименования переменных.