Pregunta

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?

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top