这个程序的有关问题出在哪里
这个程序的问题出在哪里?
void ployvalue()
{
int n,i,*a,sum=0;
float x,xp;
prinft( "Input the value of n: ");
scanf( "%d ",&n); /*输入n值*/
if(NULL == (a = (int*)malloc(sizeof(int)*n)) )
{
printf( "memory error!\n ");
exit(1);
}
printf( "Input the %d coefficients from a0 to a%d:\n ",n,n)
for(i=0; i <n; i++)
{
scanf( "%d ",&a[i]); /*输入a[n]值*/
}
printf( "Input value of x: ");
scanf( "%f ",&x); /*输入x值*/
xp = 1; sum = 0;
for(i=0; i <=n; i++)
{
sum += xp * (*a++);
xp *= x;
}
printf( "Value is: %f ", sum);
}
main()
{
ployvalue();
}
------解决方案--------------------
#include <stdlib.h>
void ployvalue()
{
int n,i,*a,sum=0;
float x,xp;
printf( "Input the value of n: ");//printf
scanf( "%d ",&n); /*输入n值*/
if(NULL == (a = (int*)malloc(sizeof(int)*n)) )
{
printf( "memory error!\n ");
exit(1);//调用exit要加头文件#include <stdlib.h>
}
printf( "Input the %d coefficients from a0 to a%d:\n ",n,n);//少了分号
for(i=0; i <n; i++)
{
scanf( "%d ",&a[i]); /*输入a[n]值*/
}
printf( "Input value of x: ");
scanf( "%f ",&x); /*输入x值*/
xp = 1; sum = 0;
for(i=0; i <=n; i++)
{
sum += xp * (*a++);
xp *= x;
}
printf( "Value is: %f ", sum);
}
main()
{
ployvalue();
}
------解决方案--------------------
sum的类型,你创建的是int类型
输出时用%f格式。
void ployvalue()
{
int n = 0,
i = 0;
int* a = NULL;
float x = 0,
xp = 0,
sum = 0;
printf( "Input the value of n: ");
scanf( "%d ", &n);
a = (int*)malloc(sizeof(int) * n);
if(NULL == a)
{
printf( "memory error!\n ");
exit(1);
void ployvalue()
{
int n,i,*a,sum=0;
float x,xp;
prinft( "Input the value of n: ");
scanf( "%d ",&n); /*输入n值*/
if(NULL == (a = (int*)malloc(sizeof(int)*n)) )
{
printf( "memory error!\n ");
exit(1);
}
printf( "Input the %d coefficients from a0 to a%d:\n ",n,n)
for(i=0; i <n; i++)
{
scanf( "%d ",&a[i]); /*输入a[n]值*/
}
printf( "Input value of x: ");
scanf( "%f ",&x); /*输入x值*/
xp = 1; sum = 0;
for(i=0; i <=n; i++)
{
sum += xp * (*a++);
xp *= x;
}
printf( "Value is: %f ", sum);
}
main()
{
ployvalue();
}
------解决方案--------------------
#include <stdlib.h>
void ployvalue()
{
int n,i,*a,sum=0;
float x,xp;
printf( "Input the value of n: ");//printf
scanf( "%d ",&n); /*输入n值*/
if(NULL == (a = (int*)malloc(sizeof(int)*n)) )
{
printf( "memory error!\n ");
exit(1);//调用exit要加头文件#include <stdlib.h>
}
printf( "Input the %d coefficients from a0 to a%d:\n ",n,n);//少了分号
for(i=0; i <n; i++)
{
scanf( "%d ",&a[i]); /*输入a[n]值*/
}
printf( "Input value of x: ");
scanf( "%f ",&x); /*输入x值*/
xp = 1; sum = 0;
for(i=0; i <=n; i++)
{
sum += xp * (*a++);
xp *= x;
}
printf( "Value is: %f ", sum);
}
main()
{
ployvalue();
}
------解决方案--------------------
sum的类型,你创建的是int类型
输出时用%f格式。
void ployvalue()
{
int n = 0,
i = 0;
int* a = NULL;
float x = 0,
xp = 0,
sum = 0;
printf( "Input the value of n: ");
scanf( "%d ", &n);
a = (int*)malloc(sizeof(int) * n);
if(NULL == a)
{
printf( "memory error!\n ");
exit(1);