There are several errors in your code, I believe because you are a beginner!
I recommend reading about printf and scanf functions
Read this answer too Difference between %i and %d
Your functional code looks like this:
#include <stdio.h>
int main()
{
double valor1, valor2;
scanf ( "%lf", &valor1);
scanf ( "%lf", &valor2);
if ( valor1>valor2){
printf("%f", valor1);
}
else if (valor1 < valor2){
printf("%f", valor2);
}
}
Just a small hint, as you will compare only 2 variables, could do with the structure if-else
instead of if-elseif
:
#include <stdio.h>
int main()
{
double valor1, valor2;
scanf ( "%lf", &valor1);
scanf ( "%lf", &valor2);
if ( valor1>valor2){
printf("%f", valor1);
}
else {
printf("%f", valor2);
}
}
As recalled by the Cat, there is still a third possibility using ternary operator, or conditional operator:
Read on this question: When should I use the "?" operator in C?
#include <stdio.h>
int main()
{
double valor1, valor2, resultado;
scanf ( "%lf", &valor1);
scanf ( "%lf", &valor2);
resultado = valor1 > valor2 ? valor1 : valor2;
printf("%f", resultado);
}
Did the answer solve your question? Do you think you can accept it? See tour if you don’t know how to do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Luiz Augusto