C
c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <stdio.h>
#include <string.h>
int main() {
//no need for explicit malloc and strcpy if function is declared inside main
void split(double d){
//buf to store string version of d
char buf[50];
//stringify d using sprintf
sprintf(buf, "%.10f", d);
//display buf
printf("number: %s\n", buf);
//use strtok to split at "."
char* res[] =
{strtok(buf, "."), strtok(NULL, " ")};
//display result
printf("integer part: %s\nfractional part: 0.%s\n\n", res[0],res[1]);
}
//tests
split(123.456);
split(1.4578989);
//rounding errors here
split(156476667.000010000);
split(1.000000/0.000005);
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run