Create a program that introduces a two-dimensional array of integers from the keyboard, puts in a one-dimensional array the sum of non-negative elements in rows, displays this array on the screen before the first zero element and displays the number of remaining elements.

#include "stdafx.h" #include <iostream> using namespace std; int main() { setlocale(LC_ALL, "Russian"); int i, j, n, m; cout << "n="; cin >> n; cout << "m="; cin >> m; int**mas = new int*[n]; for (i = 0; i < n; i++) { mas[i] = new int[m]; } for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> mas[i][j]; } } cout << "_ _ _ _ _ _ _ _ "<<"\n"; int *mas1 = new int[n]; for (i = 0; i < n; i++) { int sum = 0; for (j = 0; j < m; j++); { if (mas[i][j] >= 0) sum += mas[i][j]; mas1[i] = sum; } } for (i = 0; i < n; i++) { cout <<mas1[i]<< " "; } system("pause"); return 0; } 

example of the program. sum displays as zero

Closed due to the fact that user194374, AK , aleksandr barakin , Vadim Ovchinnikov , pavel Jan 8 '17 at 8:15 am off topic .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Community spirit, AK, aleksandr barakin, Vadim Ovchinnikov, pavel
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • for me it feels right. no negative elements, that's 0 0 - Senior Pomidor
  • four
    I finally saw this code alive :) I always believed that for(....); { ... } for(....); { ... } - this is the notion of authors of textbooks ... - Harry

1 answer 1

You have a semicolon

 for (j = 0; j < m; j++); ^^^ 

Take her away.

Logically, it was better to write cycles as

 for (i = 0; i < n; i++) { int sum = 0; for (j = 0; j < m; j++) { if (mas[i][j] >= 0) sum += mas[i][j]; } mas1[i] = sum; }