Ok, so I'm just getting the hang of this floating point thing and I decided to write a couple of quick programs to illustrate the difference between that and int. I got it to divide 5/2 and get 2 with the variable being an integer but this code isn't working to make it equal to 2.5:
#include<stdio.h>
float main()
{
float x;
x=5/2;
printf("%f", x);
}
Any help please?
3 replies to this topic
#1
Posted 21 March 2011 - 02:25 PM
|
|
|
#2
Posted 21 March 2011 - 02:48 PM
5/2 is ALWAYS 2, regardless of the data type being assigned to.
5/2.0 is 2.5.
5/2.0 is 2.5.
#3
Posted 21 March 2011 - 02:51 PM
Oh OK, thanks very much
#4
Posted 22 March 2011 - 06:43 AM
A conclusion is where you got tired of thinking.
#define class struct // All is public.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









