-3
Greetings!
I’m a beginner in programming and found this problem in a code: Segmentation fault (core dumped), after entering the first variable.
That is the code:
#include <stdio.h>
#include <math.h>
/*Elabore um algoritmo que permita a entrada de dois valores (x e y) e escreva como resultado o maior entre eles, usando apenas duas variaveis. */
int main()
{
int x, y;
//inserindo e processando os numeros
printf("Digite um valor para x:\n", &x);
scanf("%d", x);
printf("Digite um valor para y:\n", &y);
scanf("%d", y);
//condicoes para aparecer o maior
if(x > y){
printf("%d\n", x);
}else{
if (x == y)
printf("OS NUMEROS SAO IGUAIS A %d",x);
else
printf("%d",y);
}
}
That’s what comes up in relation to what’s wrong, but I couldn’t understand.
[lista03questao01.c 2021-08-21 23:33:48.604]
,,lista03questao01.c: In function ‘main’:
lista03questao01.c:11:16: warning: too many arguments for format [-Wformat-extra-args]
11 | printf("Digite um valor para x:\n", &x);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lista03questao01.c:12:17: warning: format ‘%d’ expects argument of type ‘int *’, but
argument 2 has type ‘int’ [-Wformat=]
12 | scanf("%d", x);
| ~^ ~
| | |
| | int
| int *
lista03questao01.c:13:16: warning: too many arguments for format [-Wformat-extra-args]
13 | printf("Digite um valor para y:\n", &y);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lista03questao01.c:14:17: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int’ [-Wformat=]
14 | scanf("%d", y);
| ~^ ~
| | |
| | int
| int *
Sorry if the doubt is very basic, I tried to search for answers to other questions, but found only for other cases and could not adapt to mine. Thank you very much to anyone who can help!