hello i coding a program that need to sum array according to its num
like for example num[0] will only do that and num[1]
sum[1]=num[0] +num[1];
sum[2]=num[0] +num[1] +num[2]; etc
i got one idea first i will fill the num array with numbers
then i go through after that with a for loop to fill the nums so like 0 it will only run 1 time and 1 will run 2 times etc
but code i think it returns memory addr not nums i think
anyways here my code

#include <stdio.h>
#define SIZE 8
void Parsethem(int *num,int *sum,int i)
{
     int x=i;
     for(x=0;x<i;x++) 
          sum[i]+=num[i];
}
int main(void)
{
    int num[SIZE];
    int sum[SIZE];
    int i;
    int x=2;
    for(i=0;i<8;i++) {
        num[i]=x;
        x*=2;
    }
    for(i=0; i< 8 ;i++)
        Parsethem(num,sum,i);
    for(i=0 ; i<8 ; i++)
       printf("%d\n",sum[i]);
    getchar();
    return 0;
}
       
/* with normal fashion we do this by lets say array[0] we just that so array[1] sum[1]=array[0] + array[1] */

lolz nvm i did wrong stuff acctually i didnt intilise sum to anything so it was += the memory it had lolz

#include <stdio.h>
#define SIZE 8
void Parsethem(int *num,int *sum,int i)
{
     int x=i;
     for(x=0;x<i;x++) 
          sum[i]+=num[i];
}
int main(void)
{
    int num[SIZE];
    int sum[SIZE]={0};
    int i;
    int x=2;
    for(i=0;i<8;i++) {
        num[i]=x;
        x*=2;
    }
    for(i=0; i< 8 ;i++)
        Parsethem(num,sum,i);
    puts("thats sum\n");
    for(i=0 ; i<8 ; i++)
       printf("%d ",sum[i]);
    puts("\nthose are normal nums\n");
    for(i=0;i<8;i++)
        printf("%d ",num[i]);
    getchar();
    return 0;
}
       
/* with normal fashion we do this by lets say array[0] we just that so array[1] sum[1]=array[0] + array[1] */

i m sorry for this lame post :P

This question has already been answered. Start a new discussion instead.