-
how do you use exp()
hello, can someone tell me how to use the exp() function
I've tried running this:
#include <stdio.h>
#include <math.h>
main()
{
double ans ;
ans = exp ( (float) 1 ) ;
printf("%d",ans);
the answer it keeps giving me is: -1961601175
it should be: 2.71828...
what am I doing wrong?
thank you
-
You're using printf incorrectly. printf interprets the %d flag to mean "print as an integer." This causes printf to treat 'ans' as an integer.
However, 'ans' is a double, a completely different format for storing numbers. Use %f instead of %d, so that printf interprets the contents of ans as a double.