0
#include <stdio.h>

int main()
{
int a, b, c;

c = a * b;
printf("a는?: ");
scanf("%d", &a);
printf("b는?: ");
scanf("%d", &b);
printf("%d * %d = %d ", a, b, c);

return 0;
}

i made a calculation program . but the result is wrong.

if i put 5,10 in a,b c should be 50(510) but the result is 0 i used ab instead of c . then it was solved. but i want to use c variation. what is the problem? should i use double instead of int? please tell me the reason why the problem evoked

  • 2
    The code is performing the multiplication "before" you ask the user for the numbers. Move `c = a * b;` before the last `printf` – JohnG Oct 23 '20 at 02:51

1 Answers1

2

You're assigning c = a * b at a point when a and b doesn't have proper values. You should do this calculation after assigning values to a and b, otherwise result will be some garbage value.

Right way to do it:

#include <stdio.h>

int main()
{
int a, b, c;

printf("a는?: ");
scanf("%d", &a);
printf("b는?: ");
scanf("%d", &b);

c = a * b;
printf("%d * %d = %d ", a, b, c);

return 0;
}
Aniket Tiratkar
  • 798
  • 6
  • 16