#include<stdio.h>
# define words 10
char GET(char* st, int n,char* ma);
int main() {
char ch[words];
char str[words];
int i = 0;
while (fgets(ch, words, stdin) != NULL && ch[i] != '\0' && ch[i] != '\t' && ch[i] != '\n'&&i<words) {
i++;
}
GET(ch, words, str);
fputs(str, stdout);
}
char GET(char* st, int n,char* ma) {
for (st; *st!=0; st++) {
*ma = *st;
ma++;
}
*ma = 0;
return 0;
}
这么写,供参考:
#include<stdio.h>
# define words 10
void GET(char* st, int n);
int main() {
char str[words];
GET(str, words);
puts(str);
}
void GET(char* st, int n) {
int i = 0;
//while ((st[i] = getchar()) && i < n) i++; // 第 1 题
while ((st[i] = getchar()) && i < n && st[i] != ' ' && st[i] != '\t' && st[i] != '\n') i++; // 第 2 题
st[i] = '\0';
}
不知道你这个问题是否已经解决, 如果还没有解决的话:注意每个案例中间需要隔一行输出且最后一个案例不再需要隔一行
第2题的错误在于解答中计算错误。正确的解答应该是:
将x=2代入多项式,得到:
2(2)^3 + 4(2)^2 - 5(2) + 1 = 2(8) + 4(4) - 10 + 1 = 16 + 16 - 10 + 1 = 23
所以答案是23,没有错误。
无需修改。