Prepare a program in C that receives 6 integer numbers and then the program should present the sum of these numbers on the screen, I could only here

Asked

Viewed 129 times

-2

int main()
{
    int N1, N2, N3;

    printf("Digite o primeiro numero: ", N1);
    scanf("%d", &N1);
    printf("Digite o segundo numero: ", N2);
    scanf("%d", &N2);
    printf("Digite o terceiro numero: ", N3);
    scanf("%d", &N3);



    system("PAUSE>>NULL");
    return 0;
}
  • 1

    What is your question? Can you only read 3 numbers? Or can you take advantage of this knowledge and read the 6 needed? You have problems with arithmetic operations and putting their result into a variable?

  • Look at this problem you can solve using repeat structures

  • I reinforce what @Jeffersonquesado said. What exactly is your doubt ? It was missing to say this, which is the most important.

1 answer

-2

There’s the corrected code, any doubt I’m here

 #include <stdio.h>

int main(int argc, char** argv)
{
  int numero, somatorio = 0; //iniciar com zero para não ter lixo de memória
  for(int i = 0; i < 6; i++)
  {
    scanf("%d",&numero);
    somatorio+=numero;  // vai somar todos os numeros que o usuario digitar
  }
   printf("%d\n",somatorio);  // mostra o resultado
   return 0;
}

Browser other questions tagged

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