
срочно помогите решить! дам много пунктов!!! пожалуйста, зачет по информатике!! в qBasiqВариант №
1Дан массив целых чисел, состоящий из 20 элементов. Заполнить его с клавиатуры.1. Найти:- сумму элементов, имеющих нечетное значение;- вывести индексы тех элементов, значения которых больше заданного числа А.2. Определить, есть ли в данном массиве положительные элементы, кратные k (k вводить с клавиатуры).

Ответы на вопрос

Program Pr1;
uses crt;
var mas:array[1..20] of integer;
i,v,a,k,x:integer;
Begin
clrscr;
writeln('Vvedite A');
readln(a);
writeln('Vvedite K');
readln(k);
for i:=1 to 20 do begin
writeln('Vvedite ',i,'-ji simvol');
readln(mas[i]);
end;
v:=0;x:=0;
for i:=1 to 20 do begin
if mas[i] mod 2<>0 then v:=v+mas[i];
if mas[i]>a then writeln('>a ',i);
if (mas[i] mod k=0) and (mas[i]>0) then x:=x+1;
end;
writeln('Summa nechetnih - ', v );
if x>0 then writeln('TRUE')
else writeln('FALSE');
end.



Problem Description
You have a task to solve for your computer science class. The problem involves working with an array of integers. Here are the specific requirements:1. You are given an array of 20 integers. You need to fill this array with values entered from the keyboard. 2. Find the following: - The sum of all elements with odd values. - The indices and values of elements that are greater than a given number, A. 3. Determine if there are any positive elements in the array that are divisible by a number, k. The value of k will be entered from the keyboard.
Let's break down the problem into smaller steps and solve it together.
Step 1: Filling the Array
To solve this problem, you need to first fill the array with values entered from the keyboard. Here's an example code snippet in Python that demonstrates how to do this:```python array = [] for i in range(20): num = int(input("Enter a number: ")) array.append(num) ```
This code prompts the user to enter a number 20 times and adds each number to the array.
Step 2: Finding the Sum of Odd Elements
To find the sum of all elements with odd values, you can iterate over the array and check if each element is odd. If it is, add it to a running sum. Here's an example code snippet in Python:```python odd_sum = 0 for num in array: if num % 2 != 0: odd_sum += num ```
Step 3: Finding Indices and Values Greater Than A
To find the indices and values of elements that are greater than a given number, A, you can iterate over the array and check if each element is greater than A. If it is, print its index and value. Here's an example code snippet in Python:```python A = int(input("Enter a number: ")) for i in range(len(array)): if array[i] > A: print("Index:", i, "Value:", array[i]) ```
Step 4: Checking for Positive Elements Divisible by k
To determine if there are any positive elements in the array that are divisible by a number, k, you can iterate over the array and check if each positive element is divisible by k. If you find such an element, you can print a message indicating that it exists. Here's an example code snippet in Python:```python k = int(input("Enter a number: ")) found = False for num in array: if num > 0 and num % k == 0: found = True break
if found: print("There is at least one positive element divisible by", k) else: print("There are no positive elements divisible by", k) ```
Conclusion
By following these steps and using the provided code snippets, you should be able to solve the problem and complete your computer science assignment. Remember to fill the array, find the sum of odd elements, find indices and values greater than A, and check for positive elements divisible by k. Good luck with your assignment!

Топ вопросов за вчера в категории Информатика







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili