You are reading in int
values using the %f
formatter flag, which is meant for float
. a
and b
are of type int
, so you want to use %d
.
Strange resoult of division in c
سؤال
My program in c gives me strange output.
#include<stdio.h>
#include <math.h>
int main() {
int a,b;
float c;
printf("Input values of a i b: \n");
scanf("%f%f",&a,&b);
c =a*(a+b)/(float)((a+b)*(a+b));
printf("Resoult of expression is: %f\n", c);
}
Resault is always like: -1.#IND00
Why does it happends?
المحلول
نصائح أخرى
Write
scanf("%d%d",&a,&b);
instead of
scanf("%f%f",&a,&b);
because %f
is used to represent float type and %d
is for integers.Since a and b are integers,so you must use %d
.
لا تنتمي إلى StackOverflow