-1
我寫了這個程序,它計算用戶輸入的x值爲8個多項式的程度。該程序運行,但是一旦我輸入8個多項式,它應該允許我輸入x的值,但是它會跳過,並向我顯示輸出。我嘗試在掃描儀功能中使用浮動和雙打,但沒有奏效。任何幫助將不勝感激,謝謝。多項式指針程序錯誤,掃描器跳過輸入
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void get_poly(double *coeff, int N);
double eval_poly(double *coeff, double base, int N);
int main(void)
{
int N = 8;
double res;
double base = 0.0;
double a[N];
double *coeff;
coeff = &a[0];
printf("Enter the eight coeffecients: \n");
scanf(" %d",&N);
get_poly(coeff, N);
printf("Enter x: \n");
scanf(" %lf", &base);
res=eval_poly(coeff, base, N);
printf("Output: %f. \n",res);
return 0;
}
void get_poly(double *coeff, int N)
{
int i = 0;
double placeholder;
for (i = 0; i < N; i++)
{
scanf(" %lf", &placeholder);
*coeff = placeholder;
coeff++;
}
}
double eval_poly(double *coeff, double base, int N)
{
int i = 0;
double res=0.0;
for (i = 0; i < N; i++)
res=res+coeff[i]*pow(base,i);
return res;
}
可能重複[Scanf跳過第二行輸入,總是](http://stackoverflow.com/questions/32958993/scanf-skips-second-line-of-input-always) –