Q:

How to find the maximum amount of diamonds in a mine?

I have to make a program that accepts as input n the amount of rows/columns for a 2d array, and the array itself.
It should calculate the maximum amount of 'diamonds' it can collect in a mine, by only going right, right up or right down.
The code doesn't give any compilation error, but when I run it, it gives a segmentation fault. 
Probably this has to do something with the malloc I use in my main, but I don't know how to fix it.
The code is:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define max(a,b) (((a)>(b))?(a):(b))

int maxdiam(int *mine, int m, int n) {
    // table for storing intermediates
    int table[m][n];

    memset(table, 0, sizeof(table));

    for(int c=n-1; c>=0; c--) {
        for (int r=0; r<m; r++) {
            // right
            int right = (c == n-1)? 0: table[r][c+1];

            // right up
            int rightup = (r == 0 || c == n-1)? 0:table[r-1][c+1];
            // right down
            int rightdown = (r == m-1 || c == n-1)? 0:
                             table[r+1][c+1];

            // Max collected
            table[r][c] = mine[r] + max(right, max(rightup, rightdown));
        }
    }

    // max diam == max first column all rows
    int res = table[0][0];

    for (int i=1; i<m; i++)
        res = max(res, table[i][0]);
    return res;
}

// Driver Code
int main(int argc, char* v[]) {
    int n;

    scanf("%d", &n);

    int m = n;
    int **mine = malloc(sizeof(int *) * n);

    for(int i = 0; i < n; i++) {
        mine[i] = (int *)malloc(n * sizeof(int));
    }

    for(int i=0; i < n; i++) {
        for(int j=0; j < n; j++) {
            scanf("%d", &mine[i][j]);
        }
    }

    printf("%d\n", maxdiam(&mine[m][n], m, n));

    return 0;
}

Expected inputs and outputs:
input:
3
1 3 3
2 1 4
0 6 4
output:
12 

input:
4
1 3 1 5
2 2 4 1
5 0 2 3
0 6 1 2
output:
16 

input:
4
10 33 13 15
22 21 4  1
5  0  2  3
0  6  1  2
output:
83 

I'm not asking for someone who gives the correct code for my problem, but I hope someone knows why I'm getting the above error and how I can fix this.

A:

There are a number of problems in your code, some of which have already been mentioned in the comments. Below, I've posted a working version (I tested it with your sample data), with comments in the code where I've made changes (all of which have the triple slash, /// to mark them).
These few problems aside, the logic of your code (how you traverse the array looking for the maximum) is fine - which is why I have posted this answer as a complete solution.
Please feel free to ask for further information and/or clarification on any of the changes I've made.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

///#define max(a,b) (((a)>(b))?(a):(b)) // Should be already defined in stdlib.h

int maxdiam(int** mine, int m, int n) { /// NOTE: "mine" is an int** - NOT an int*
    // table for storing intermediates
/// int table[m][n]; // Variable length arrays are NOT standard C, so use the following ...
    int** table = malloc(sizeof(int*) * m); // This allocates a 'm' size array of pointers ...
    for (int i = 0; i < m; ++i) {
        table[i] = malloc(sizeof(int) * n);  // ... each of which points to an 'n' size array of intregers
        memset(table[i], 0, sizeof(int) * n); // And here, we set the values to all zero.
    }
/// memset(table, 0, sizeof(table)); // This cannot be used with the 'malloc' system!
    for (int c = n - 1; c >= 0; c--) {
        for (int r = 0; r < m; r++) {
            // right
            int right = (c == n - 1) ? 0 : table[r][c + 1];
            // right up
            int rightup = (r == 0 || c == n - 1) ? 0 : table[r - 1][c + 1];
            // right down
            int rightdown = (r == m - 1 || c == n - 1) ? 0 : table[r + 1][c + 1];
            // Max collected
        /// table[r][c] = mine[r] + max(right, max(rightup, rightdown)); // You forgot the column index!
            table[r][c] = mine[r][c] + max(right, max(rightup, rightdown));
        }
    }
    // max diam == max first column all rows
    int res = table[0][0];
    for (int i = 1; i < m; i++) res = max(res, table[i][0]);

    /// Here, we free the 'temporary' array(s) we created ...
    for (int i = 0; i < m; ++i) free(table[i]);
    free(table);

    return res;
}

// Driver Code
int main(int argc, char* v[]) {
    int n;

    scanf("%d", &n);
    int m = n;
    int** mine = malloc(sizeof(int*) * n);

    for (int i = 0; i < n; i++) {
        mine[i] = malloc(n * sizeof(int)); // Note: you shouldn't "cast" the return value of malloc!
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &mine[i][j]);
        }
    }
/// printf("%d\n", maxdiam(&mine[m][n], m, n)); // This will pass the address of the first element of the last row!
    printf("%d\n", maxdiam(mine, m, n));        // Use this instead - to pass the address of the 'row' array!
    return 0;
}

NOTE: On the bit I've marked about "variable length arrays" - If your system (probably gcc) allows this, then you can continue to use that, and thus take out the system I gave using malloc and free. However, I don't think it is the best way to learn C programming.

