Error while running script

Asked

Viewed 76 times

1

#include<stdio.h>
#include<math.h>

int main ( void ){
int x;
int i;
printf("Input the number (Table to be calculated) : ");
scanf("%d", x);

for( i = 1; i <= 10; i++){

    printf("%d x %d = %d", x, i, x*i);
}
return 0;

}

inserir a descrição da imagem aqui

Would you like to know the reason for the mistake? I tried creating a variable to hold the value of x*i inside the loop, but it still doesn’t work, after I give the first input seen on the screen, Windows identifies a problem...

  • The & in the scanf(). You need to specify which memory address will receive the integer value. In this case, the address of the variable x. So pass on &x.

2 answers

5


After the first parameter, the function scanf expects to receive a reference the variable that wants to store the input value:

scanf("%d", &x);

I hope I’ve helped.

-2

in addition to the "&" in "scanf" as already mentioned, you put in the main function the void and at the end of the code "Return 0", and this is wrong because void does not return anything.

  • 3

    int main means that the return is int, and not void.

Browser other questions tagged

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