c语言 为什么运行没结果..求大神指导..怎么修改,编写程序拆分输入实数的整数部分与小数部分..#include int main(void){double x,*intpart,*fracpart;void splitfloat (double x,double *intpart,double *fracpart);printf(" ");scanf("%lf",&x);printf("The intpart is:%lf\t\n",*intpart);printf("The fracpart is:%.6lf\t ",*fracpart);return 0;}void splitfloat (double x,double *intpart,double *fracpart){*intpart=(int)x;*fracpart=x-*intpart;}
c语言 为什么运行没结果..求大神指导..怎么修改,编写程序拆分输入实数的整数部分与小数部分..
#include
int main(void)
{double x,*intpart,*fracpart;
void splitfloat (double x,double *intpart,double *fracpart);
printf(" ");
scanf("%lf",&x);
printf("The intpart is:%lf\t\n",*intpart);
printf("The fracpart is:%.6lf\t ",*fracpart);
return 0;}
void splitfloat (double x,double *intpart,double *fracpart)
{
*intpart=(int)x;
*fracpart=x-*intpart;}
#include <stdio.h>
int main(void)
{double x,y,z,*intpart=&y,*fracpart=&z;
void splitfloat (double x, double *intpart, double *fracpart);
printf(" ");
scanf("%lf", &x);
splitfloat(x, intpart, fracpart);
printf("The intpart is: %lf\t\n",*intpart);
printf("The fracpart is:%.6lf\t ",*fracpart);
return 0;}
void splitfloat (double x, double *intpart, double *fracpart)
{
*intpart=(int)x;
*fracpart=x-*intpart;}
你的两个指针都没指向具体的内存空间,往里面写内容就非法访问了.
另外,你的splitfloat函数也没调.