> 其他 >
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;}
人气:288 ℃ 时间:2020-04-04 07:17:05
解答
#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函数也没调.

推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版