Rodrigo156 Rodrigo156 -4 years ago 45
C Question

The scanf don't store my sum

When the code run, my scanf don't show the sum, just 0.00000000.

I don't know where is the problem.

int main() {

float A, B;
float R = A+B;


printf("Digita o valor A: ");
scanf("%f",&A);
printf("Digite o valor B: ");
scanf("%f",&B);
printf("A soma de %f e %f foi igual a: %f",A,B,R);

return 0; }

Answer Source

Below is the right way.

int main() {
    float A, B;
    float R;
    printf("Digita o valor A:  ");
    scanf("%f",&A);
    printf("Digite o valor B:  ");
    scanf("%f",&B);
    R = A+B;
    printf("A soma de %f e %f foi igual a: %f",A,B,R);
    return 0;
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download