Timeout the monitored command dumped core

Which is pretty much alien language to me, hence i cannot not possibly understand what the compiler is saying.

I looked up the internet , for what could be the reason and found out that i could be accessing index which has not been allocated memory, therefore i set on to make a simplest code possible and encounter the same error.

#include<stdio.h>
int main()
{
    int n;
    int a[100000];
    scanf("%d",&n);
    int j=0;
    for(int i=2;i<=n;i+2)
    {   

        if (i%2==0)
            {   
                 a[j]=i;
                 j+=1;
            }
     }
     return 0;
} 

But i don't understand how i could be accessing non allocated memory.

Also what could be the other reasons for the same error to occur such frequently.

Best Solution

I think the issue could be your for loop, as in the third part you're not updating i. To update, write it as i=i+2 or i+=2.

Related Solutions

C++ – the difference between #includeand #include “filename”

In practice, the difference is in the location where the preprocessor searches for the included file.

For

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
0 the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files.

For

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
1 the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the
int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
0 form. This method is normally used to include programmer-defined header files.

A more complete description is available in the GCC documentation on search paths.

How to determine the size of the array in C

Executive summary:

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);

Full answer:

To determine the size of your array in bytes, you can use the

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
3 operator:

int a[17];
size_t n = sizeof(a);

On my computer, ints are 4 bytes long, so n is 68.

To determine the number of elements in the array, we can divide the total size of the array by the size of the array element. You could do this with the type, like this:

int a[17];
size_t n = sizeof(a) / sizeof(int);

and get the proper answer (68 / 4 = 17), but if the type of

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
4 changed you would have a nasty bug if you forgot to change the
int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
5 as well.

So the preferred divisor is

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
6 or the equivalent
int a[17];
size_t n = sizeof(a)/sizeof(a[0]);
7, the size of the first element of the array.

I got an RTE on my submission, and I've tested it (on my local machine) on a variety of test cases, including the ones on the udebug. But on my uri submission it says "timeout: the monitored command dumped core" and I'm not sure of what i did wrong. Here's the code :

#include
using namespace std;

const int nmax = 1024;
string arr[nmax];
int n, m;

void dfs(int i, int j){
    if (arr[i][j] == 'o') return;
    arr[i][j] = 'o';
    if (i > 0) dfs(i-1, j);
    if (i < n-1) dfs(i+1, j);
    if (j > 0) dfs(i, j-1);
    if (j < m-1) dfs(i, j+1);
}

int main(){
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int cnt = 0;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            if (arr[i][j] == '.'){
                dfs(i,j);
                cnt++;
            }
        }
    }
    cout << cnt << '\n';
}

Any help would be appreciated :) Thanks in advance.

#includeusing namespace std; int main() { int ages[5]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int i; int min=ages[i]; for (int i =0; i<5; ++i){ if ( ages[i] >min){ min = ages [i]; } } int price; price = 50 * min / 100; cout << price << endl; return 0; }