``````unsigned long nBolum = 0L;
unsigned long nKalan = 0L;
unsigned long ulA = 0L;
unsigned long ulB = 0L;
...
printf("ulA=%u\n",ulA);
printf("ulB=%u\n",ulB);
nBolum = (unsigned long) ulA/ulB;
nKalan = (unsigned long) ulA%ulB;
printf("nBolum = %u\n",nBolum);
printf("nKalan = %u\n",nKalan);
printf("HVFE.c exiting\n");
exit(1);``````

it prints :

``````ulA=2607503366
ulB=16777215

nBolum = 65435
nKalan = 7100321``````

to the screen.

but nBolum must be 155.419.... Why is this happenning?

thanx.

## All 3 Replies

You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.

And dividing two integers always gives an integer, even if you load it into a floating point number. For example:

``````double dval;
dval = 25/2;``````

12.000 is loaded into dval, not 12.5.

You can't possibly get 155.419 from an unsigned long, there is no decimal point from integers. You need float or double.

And dividing two integers always gives an integer, even if you load it into a floating point number. For example:

``````double dval;
dval = 25/2;``````

12.000 is loaded into dval, not 12.5.

i want to get 155 as integer.

``````unsigned long nBolum = 0L;
/* I have changed this line to : */
/* unsigned int nBolum = 0; */

unsigned long nKalan = 0L;
unsigned long ulA = 0L;
unsigned long ulB = 0L;
...
printf("ulA=%u\n",ulA);
printf("ulB=%u\n",ulB);
nBolum = (unsigned long) ulA/ulB;

/* I have changed this line to : */
/* nBolum = (unsigned int) ulA/ulB;*/

nKalan = (unsigned long) ulA%ulB;
printf("nBolum = %u\n",nBolum);
printf("nKalan = %u\n",nKalan);
printf("HVFE.c exiting\n");
exit(1);``````

it prints :

``````ulA=2607503366
ulB=16777215

nBolum = 65435
nKalan = 7100321``````

to the screen.

but nBolum must be 155.419.... Why is this happenning?

thanx.

change the line above and nBolum problem is gone. But I also see that nKalan is not being calculated correctly. I have opened another topic for the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.