N
NoKetch
I have a simple program to output log2(x) but the result is not whole numbers.
Here is the code:
----------------------
#include <stdio.h>
#include <math.h>
int main()
{
double x;
printf("Enter a Number: ");
scanf( "%lf", &x);
if ( x >= 0 )
printf("\nResult: %lf\n", log2(x));
system("PAUSE");
return 0;
}
----------------------
I get results like this:
Result: 4.321928
Result: 5.459432
How do i round these numbers to the next highest whole number so that the
output would be:
Result: 5
Result: 6
I'm not a very experienced programmer, so the explanation should be fairly
simple.
Thanks for any tips
Dave
Here is the code:
----------------------
#include <stdio.h>
#include <math.h>
int main()
{
double x;
printf("Enter a Number: ");
scanf( "%lf", &x);
if ( x >= 0 )
printf("\nResult: %lf\n", log2(x));
system("PAUSE");
return 0;
}
----------------------
I get results like this:
Result: 4.321928
Result: 5.459432
How do i round these numbers to the next highest whole number so that the
output would be:
Result: 5
Result: 6
I'm not a very experienced programmer, so the explanation should be fairly
simple.
Thanks for any tips
Dave