mirogall
?>

Написать программу с использованием оператора while в результате работы которой осуществляется вывод последовательности чисел 9 7 5 3 1

Информатика

Ответы

Yurii537
Int i = 9;
while (i  <= 1) {
     print(i);
     i = i -2;
}
igor51766771
Program yeah;const N=15;const M=15;var A:array [1..N,1..M] of integer;i,j,b,c,x,y:integer;beginrandomize;write('матрица: ');writeln;for i:=1 to N do begin   for j:=1 to M do beginA[i,j]:=random(100);write(A[i,j]:3);end;writeln;end;c:=1;while c<16 do beginfor i:=1 to N do begin   for j:=1 to M do beginb:=A[1,c];end;end;x:=x+b;c:=c+1;end;writeln('сумма первой строчки: ',x);c:=1;while c<16 do beginfor i:=1 to N do begin   for j:=1 to M do beginb:=A[15,c];end;end;y:=y+b;c:=c+1;end;writeln('сумма последней строчки: ',y);x:=x+y;writeln('общая сумма: ',x);end.
diana-020
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
using namespace std;
typedef unsigned short int USI;

int* fillArray(string name, int s);
int maxArray(int[], int s);
bool isPrime(int);
void deleteAllEqualTo(int[], int s, int value);
float averageOfPositive(int[], int s);
void printArray(int[], int s);

bool sortByDescAbs(int i, int j) {
return abs(i) > abs(j);
}

int main() {
setlocale(LC_ALL, "Russian");
USI n;
cout << "n = ";
cin >> n;
int* z = fillArray("z", n);
int max = maxArray(z, n);
if ( isPrime(max) ) {
deleteAllEqualTo(z, n, max);
}
float avg = averageOfPositive(z, n);
cout << "среднее: " << avg << '\n';
sort(z, z + n, sortByDescAbs);
cout << "z[" << n << "]: ";
printArray(z, n);
return 0;
}

int* fillArray(string name, int s) {
int array[s];
for (int i = 0; i < s; i++) {
cout << name << "[" << i << "] = ";
cin >> array[i];
}
return array;
}

int maxArray(int a[], int s) {
int max = a[0];
for (int i = 1; i < s; i++) {
if (a[i] > max) max = a[i];
}
return max;
}

bool isPrime(int n) {
if (n < 2) return false;
if (n == 2) return true;
if (n % 2 == 0) return false;
for (int i = 3; (i*i) <= n; i += 2) {
if (n % i == 0 ) return false;
}
return true;
}

void deleteAllEqualTo(int a[], int s, int value) {
for (int i = 0; i < s; i++) {
if (a[i] == value) a[i] = 0;
}
}

float averageOfPositive(int a[], int s) {
unsigned int sum = 0,
count = 0;
for (int i = 0; i < s; i++) {
if (a[i] > 0) {
sum += a[i];
count++;
}
}
return (sum / count);
}

void printArray(int a[], int s) {
for (int i = 0; i < s; i++) {
cout << a[i] << ' ';
}
}

Ответить на вопрос

Поделитесь своими знаниями, ответьте на вопрос:

Написать программу с использованием оператора while в результате работы которой осуществляется вывод последовательности чисел 9 7 5 3 1
Ваше имя (никнейм)*
Email*
Комментарий*

Популярные вопросы в разделе

krikatiy
rs90603607904
tanyatanyat
donliolik
Мартынова1638
nst-33764
Dmitrievich-Telishev
Galina-3639220565
yuklimochkina3
sklad2445
AlidzhanovDenis491
avdoyan6621
Anastasiya81
alex091177443
Иванович621