Array problem in C, where is the error?

Asked

Viewed 140 times

2

I have the following problem to solve: inserir a descrição da imagem aqui

I arrived at this solution:

    #include <stdio.h>
int main()
{

    double numeros[99];
    double resultante[49];

    int i, j;

    for (i = 0; i <= 99; i++)
    {
        scanf("%d",&numeros[i]);
    }

    for(i=0;i<=49;i++)
    {
        resultante[i] = numeros[i]*numeros[100-i];
    }

    for(i=0;i<=49;i++)
    {
        printf("%d",resultante[i]);
    }

    return 0;
}

I wonder why this code isn’t working, the returns are weird, they look like addresses, but I’m not sure.

1 answer

5


First of all if there are 100 elements you must declare double numeros[100], resultante[50]; not 99 and 49 as stated. Note that for 100 elements the array index will vary from 0 to 99.

Failed to calculate the sum as requested in the problem.

#include <stdio.h>
int main() {
    double numeros[100], resultante[50], soma=0;
    int i, j;
    for (i = 0; i <= 99; i++) {
        scanf("%d",&numeros[i]);
    }
    for(i=0;i<=49;i++) {
        resultante[i] = numeros[i]*numeros[99-i];
        soma += resultante[i];
    }
    for(i=0;i<=49;i++) {
        printf("\t%d",resultante[i]);
    }
    printf("\nSoma: %d\n", soma);
    return 0;
}
  • can you answer my question? https://answall.com/questions/469237/identificar-registrations-sequentialof each user

Browser other questions tagged

You are not signed in. Login or sign up in order to post.