Создайте 5 переменных типа char, предложите пользователю ввести слово из пяти букв и покажите эти символы (слово) на экран. (символы вводить латиницей, т.к. кирилица будет отображаться некорректно.
Ответы на вопрос:
Данная программа находит именно сумму между элементами в массиве:
using System;
class main{
static void Main() {
Console.Write("Введите кол-во элементов в массиве: ");
int N = Convert.ToInt32(Console.ReadLine());
int[] myArr = new int[N];
for (int i = 0; i < N; i++)
{
Console.Write("Введите элемент: ");
myArr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("Введите начало отрезка: ");
int a = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите конец отрезка: ");
int b = Convert.ToInt32(Console.ReadLine());
int[] list = new int[N];
bool flag = false;
for (int i = 0; i < myArr.Length; i++)
{
if (a == myArr[i]) {
flag = true;
}
if (flag == true) {
list[i] = (myArr[i]);
if (b == myArr[i]) break;
}
}
int count = Convert.ToInt32(0);
for (int i = 0; i < list.Length; i++) {
if (list[i] > 0) count += list[i];
}
Console.Write("Сумма: ");
Console.Write(count);
}
}
Эта программа находит сумму между индексами элементов в массиве в массиве (если считать от 1):
using System;
class main {
static void Main() {
Console.Write("Введите кол-во элементов в массиве: ");
int N = Convert.ToInt32(Console.ReadLine());
int[] myArr = new int[N];
for (int i = 0; i < N; i++)
{
Console.Write("Введите элемент: ");
myArr[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("Введите начало отрезка: ");
int a = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите конец отрезка: ");
int b = Convert.ToInt32(Console.ReadLine());
int[] list = new int[N];
bool flag = false;
for (int i = 0; i < myArr.Length; i++)
{
if (a == i + 1) {
flag = true;
}
if (flag == true) {
list[i] = myArr[i];
if (b == i + 1) break;
}
}
int count = 0;
for (int i = 0; i < list.Length; i++) {
if (list[i] > 0) count += list[i];
}
Console.Write("Сумма: ");
Console.Write(count);
}
}
Популярно: Информатика
-
Даріна1111111121.09.2021 17:25
-
kuchakshoevaZ19.09.2021 00:15
-
wiamous129.01.2022 03:29
-
karina3651714.04.2020 13:21
-
МахитоТ11.11.2020 17:16
-
Anastasya15604.03.2023 07:26
-
Mishgan2110.05.2020 03:41
-
sergeirasnei12.09.2020 04:33
-
deadpool247819.01.2022 01:32
-
artem16021artemka1613.02.2022 01:12