Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute C Online

#include <stdio.h>

int arraysum(int*, int);
void arrprint(int*, int);

int main()
{
    int in[] = {3,-4,2,9,5,1,7};
    
    arraysum(in, 7);

    return 0;
}

int arraysum(int* in, int sz)
{
    int* arr = NULL;
    int i,j,k;
    int maxsum = 0; 
    
    arr = (int*) malloc (sz*sz*sizeof(int));
    
    memset (arr, 0, sz*sz*sizeof(int));
    
    for (i = 0; i < sz; i++) {
        for (j = i; j < sz; j++) {
            arr[i*sz + j] += in[i];
        }
        for (j = i - 1; j >= 0; j--) {
            for (k = i; k < sz; k++) {
              arr[j*sz + k] += in[i];
            }
        }
    }
    arrprint(arr, sz);
    
}

void arrprint(int* in, int sz)
{
    int i, j;
    
    for (i = 0; i < sz; i++) {
        for (j = 0; j < sz; j++) {
            printf ("%d  ", in[i*sz + j]);
        }
        printf("\n");
    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.