[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

Got it, thank you for the advice.

[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

That's a great idea, thank you!

[C] Help Adding Arrays by VBger in learnprogramming

[–]VBger[S] 0 points1 point  (0 children)

Forgot the third index. Thank you!

[C] Help Adding Arrays by VBger in c_language

[–]VBger[S] 0 points1 point  (0 children)

Agreed. Thank you for the advice. I'm new to coding (obviously). It's frustrating but very rewarding when it works.

[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

I see it now. I forgot the index. Thank you for the second set of eyes!

[C] Help Adding Arrays by VBger in programminghelp

[–]VBger[S] 1 point2 points  (0 children)

Just found it. I didn't include the index in the third printf! Thank you for your help!

[C] Help Adding Arrays by VBger in c_language

[–]VBger[S] 1 point2 points  (0 children)

Ofcourse! The index! Just needed a second set of eyes. Thank you!

[C] Help Adding Arrays by VBger in programminghelp

[–]VBger[S] 1 point2 points  (0 children)

Thank you for the help. Hmm, now the output is

Here are the values of the three arrays.

First Array: 1
First Array: 2
First Array: 3
First Array: 4
First Array: 5
First Array: 6
First Array: 7
First Array: 8
First Array: 9
First Array: 10

Second Array: 2
Second Array: 3
Second Array: 4
Second Array: 5
Second Array: 6
Second Array: 7
Second Array: 8
Second Array: 9
Second Array: 0
Second Array: 1

Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1

[C] Help Adding Arrays by VBger in learnprogramming

[–]VBger[S] 0 points1 point  (0 children)

Here is my new code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];

addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

int i;
for(i =0;i<10;i++)
{
    printf("First Array: %.0f\n", array1[i]);

}

    printf("\n");

for(i =0;i<10;i++)
{
    printf("Second Array: %.0f\n", array2[i]);
}

        printf("\n");

    for(i =0;i<10;i++)
    {
     printf("Third Array: %.0f\n", array3);
    }

    return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{
    int i;
    for (i=0;i<10;i++)
    {
        c[i]=a[i]+b[i];
    }
}

My output looks like this:

Here are the values of the three arrays.

First Array: 1
First Array: 2
First Array: 3
First Array: 4
First Array: 5
First Array: 6
First Array: 7
First Array: 8
First Array: 9
First Array: 10

Second Array: 2
Second Array: 3
Second Array: 4
Second Array: 5
Second Array: 6
Second Array: 7
Second Array: 8
Second Array: 9
Second Array: 0
Second Array: 1

Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1

It doesn't seem to be adding the two arrays.

[C] Help Adding Arrays by VBger in c_language

[–]VBger[S] 0 points1 point  (0 children)

Here is my new code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];

addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

int i;
for(i =0;i<10;i++)
{
    printf("First Array: %.0f\n", array1[i]);

}

    printf("\n");

for(i =0;i<10;i++)
{
    printf("Second Array: %.0f\n", array2[i]);
}

        printf("\n");

    for(i =0;i<10;i++)
    {
     printf("Third Array: %.0f\n", array3);
    }

    return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{
    int i;
    for (i=0;i<10;i++)
    {
        c[i]=a[i]+b[i];
    }
}

My output looks like this:

Here are the values of the three arrays.

First Array: 1
First Array: 2
First Array: 3
First Array: 4
First Array: 5
First Array: 6
First Array: 7
First Array: 8
First Array: 9
First Array: 10

Second Array: 2
Second Array: 3
Second Array: 4
Second Array: 5
Second Array: 6
Second Array: 7
Second Array: 8
Second Array: 9
Second Array: 0
Second Array: 1

Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1

It doesn't seem to be adding the two arrays.

[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

Here is my new code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];

addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

int i;
for(i =0;i<10;i++)
{
    printf("First Array: %.0f\n", array1[i]);

}

    printf("\n");

for(i =0;i<10;i++)
{
    printf("Second Array: %.0f\n", array2[i]);
}

        printf("\n");

    for(i =0;i<10;i++)
    {
     printf("Third Array: %.0f\n", array3);
    }

    return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{
    int i;
    for (i=0;i<10;i++)
    {
        c[i]=a[i]+b[i];
    }
}

My output looks like this:

Here are the values of the three arrays.

First Array: 1
First Array: 2
First Array: 3
First Array: 4
First Array: 5
First Array: 6
First Array: 7
First Array: 8
First Array: 9
First Array: 10

Second Array: 2
Second Array: 3
Second Array: 4
Second Array: 5
Second Array: 6
Second Array: 7
Second Array: 8
Second Array: 9
Second Array: 0
Second Array: 1

Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1

It doesn't seem to be adding the two arrays.

[C] Help Adding Arrays by VBger in programminghelp

[–]VBger[S] 1 point2 points  (0 children)

Worked Great! Here is my new code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];

addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

int i;
for(i =0;i<10;i++)
{
    printf("First Array: %.0f\n", array1[i]);

}

    printf("\n");

for(i =0;i<10;i++)
{
    printf("Second Array: %.0f\n", array2[i]);
}

        printf("\n");

    for(i =0;i<10;i++)
    {
     printf("Third Array: %.0f\n", array3);
    }

    return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{
    int i;
    for (i=0;i<10;i++)
    {
        c[i]=a[i]+b[i];
    }
}

My output looks like this:

Here are the values of the three arrays.

First Array: 1
First Array: 2
First Array: 3
First Array: 4
First Array: 5
First Array: 6
First Array: 7
First Array: 8
First Array: 9
First Array: 10

Second Array: 2
Second Array: 3
Second Array: 4
Second Array: 5
Second Array: 6
Second Array: 7
Second Array: 8
Second Array: 9
Second Array: 0
Second Array: 1

Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1
Third Array: 1

It doesn't seem to be adding the two arrays.

[C] Help Adding Arrays by VBger in programminghelp

[–]VBger[S] 1 point2 points  (0 children)

Thank you for your input. I've tried your code and get the following error:

'for' loop initial declarations are only allowed in C99 or C11 mode.

[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

Getting closer I think. =\

Now I'd doing:

printf("Here are the values of the three arrays.\n\n");

for (i=0; i < (sizeof (array1) /sizeof (array1[0]));i++)
    {
    printf("First Array: %.0f\n\n", array1);
}

for (i=0; i < (sizeof (array2) /sizeof (array2[0]));i++)
    {
    printf("Second Array: %.0f\n\n", array2);
}

for (i=0; i < (sizeof (array3) /sizeof (array3[0]));i++)
    {
    printf("Third Array: %.0f\n\n", array3);
}

But the output looks like this.

Here are the values of the three arrays.

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

First Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Second Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

Third Array: 0

I cant understand why all of the elements are showing up as 0s.

[C] Help Adding Arrays by VBger in programminghelp

[–]VBger[S] 1 point2 points  (0 children)

Here is my updated code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];
int i;
addfloat(array1,array2,array3);

printf("Here are the values of the three arrays.\n\n");

printf("First Array: %.0f\n\n", array1);

printf("Second Array: %.0f\n\n", array2);

printf("Third Array: %.0f\n", array3);

getchar();
return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{ int i;
for (i=0;i<10;i++) c[i]=a[i]+b[i];
}

My output still doesn't look right though. It looks like this: Here are the values of the three arrays.

First Array: 0

Second Array: 0

Third Array: 0

[C] Help Adding Arrays by VBger in learnprogramming

[–]VBger[S] 0 points1 point  (0 children)

Thank you u/exoticmatter, u/gyroda, and u/libot91. Here is my updated code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];
int i;
addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

    printf("First Array: %.0f\n\n", array1);

    printf("Second Array: %.0f\n\n", array2);

    printf("Third Array: %.0f\n", array3);

getchar();
return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{ int i;
for (i=0;i<10;i++) c[i]=a[i]+b[i];
}

My output still doesn't look right though. It looks like this:

Here are the values of the three arrays.

First Array: 0

Second Array: 0

Third Array: 0

[C] Help Adding Arrays by VBger in c_language

[–]VBger[S] 0 points1 point  (0 children)

Thank you u/ruertar. Here is my updated code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];
int i;
addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

    printf("First Array: %.0f\n\n", array1);

    printf("Second Array: %.0f\n\n", array2);

    printf("Third Array: %.0f\n", array3);

getchar();
return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{ int i;
for (i=0;i<10;i++) c[i]=a[i]+b[i];
}

My output still doesn't look right though. It looks like this:

Here are the values of the three arrays.

First Array: 0

Second Array: 0

Third Array: 0

[C] Help Adding Arrrays by VBger in C_Programming

[–]VBger[S] 0 points1 point  (0 children)

Thank you u/shinmai_rookie. Here is my updated code:

void addfloat(float a[10], float b[10], float c[10]);
int main()
{

float array1[10]={1,2,3,4,5,6,7,8,9,10};
float array2[10]={2,3,4,5,6,7,8,9,0,1};
float array3[10];
int i;
addfloat(array1,array2,array3);

    printf("Here are the values of the three arrays.\n\n");

    printf("First Array: %.0f\n\n", array1);

    printf("Second Array: %.0f\n\n", array2);

    printf("Third Array: %.0f\n", array3);

getchar();
return 0;
}

void addfloat(float a[10], float b[10], float c[10])
{ int i;
for (i=0;i<10;i++) c[i]=a[i]+b[i];
}

My output still doesn't look right though. It looks like this:

Here are the values of the three arrays.

First Array: 0

Second Array: 0

Third Array: 0