#include<stdio.h> #include<math.h> int main() { float a=5.375; char *p; int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0; }
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int num1 = 12345;
float num2 = 5.12;
char str1[20];
char str2[20];
itoa(num1, str1, 10); /* 10 radix value */
printf("integer = %d string = %s \n", num1, str1);
sprintf(str2, "%f", num2);
printf("float = %f string = %s", num2, str2);
return 0;
}
// Output:
// integer = 12345 string = 12345
// float = 5.120000 string = 5.120000
/* Prints a random number in the range 0 to 99 */
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(void)
{
randomize();
printf("Random number in the 0-99 range: %d\n", random (100));
return 0;
}
To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)
y = (int)(x + 0.5); here x is any float value. To roundoff, we have to typecast the value of x by using (int)
Example:
#include <stdio.h>
int main ()
{
float x = 3.6;
int y = (int)(x + 0.5);
printf ("Result = %d\n", y );
return 0;
}
Output:
Result = 4.
Example:
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
return 0;
}
Output:
fmod of 5.5 by 1.3 is 0.300000
Comments
There are no comments.Copyright ©CuriousTab. All rights reserved.