By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

What is floating point error in C ?

P: n/a
hello friends;

I have an error in my program what is the reason behind it.
Expand|Select|Wrap|Line Numbers
  1. /*this is mathematical function of EXPONENT*/
  4. #include<conio.h>
  5. #include<stdio.h>
  6. #include<math.h>
  8. double exponent(float e)
  9. {
  10.  float x,i,f=20; 
  11.  float g;            
  13.   for (i=1;i<=f;i++)
  14.      {
  15.          e=pow(x,i);
  16.          g=e/(fct(i));
  17.      }
  18.   return(e);
  19. }
  21. void main()
  22. {
  23. clrscr();
  24. {
  25. double exponent(float e);
  26.     float x,y;
  27.     printf("\n insert number for exponent\t\t");
  28.     scanf("%d",&x);
  29.     y=exponent(x);
  30.     printf("\n\n the exponent value is%d",y);
  31. }
  32. getch();
  33. }
please help me and find out why the program is not running succesfully.
Oct 20 '10 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 100+
P: 931
You have taken float variables and in print and scan functions you are using %d. I think %f will help get rid of this error.
Oct 20 '10 #2

P: 10
Probable reasons for a floating point exception include:
Overflow on signed types
Division by zero.

There is no function called fct() in math.h
Also you are using pow() function on two uninitialized float variables.
I think pow() function is giving the exception.
Oct 23 '10 #3

Expert 100+
P: 2,396
It would help immensely if you told us what error you're getting. Compiler error? Linker error? Run-time error? Incorrect result? Don't make us guess.

What is the purpose of the loop in lines 13-17? As far as I can see, each pass through the loop discards all of the work of the previous pass. You could simply set i to the value it gets for the last pass through the loop and execute the loop body once.

Is there any reason why you're mixing double and float variables? Why not use double throughout?

It is considered bad form to use non-integral types to control execution in a for loop. It can be done, but it is much harder to achieve your desired result than with integral types.

What is fct?
Oct 23 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.