I already know how to declare a variable in the traditional way using scanf()
, but I'm thinking in a way that I can use fewer rows and make the code more organized (this is what I tried with the variable valor
). / p>
It turns out that when I run the program the value 1 is always printed on the screen. Why is the value 1 printed on the screen?
Is there a more organized way to use scanf()
without using another line (similar to what I'm trying to do)?
Code no replit - >
#include<stdio.h>
int main()
{
int resultado = 1;
printf("Coloque um valor: ");
int valor = scanf("%d", &valor);
while (valor > 0){
resultado = resultado * valor;
valor = valor - 1;}
printf("O exponencial é: %d\n", resultado);
}