设计函数求一元多项式的导数。
输入格式:
以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。
输出格式:
以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。
输入样例:
3 4 -5 2 6 1 -2 0
输出样例:
12 3 -10 1 6 0-------------------------------------------------------------------------注意两个情况:1、常数的求导为特例情况,输出 0 02、当输入的指数不含0时,怎么处理?-------------------------------------------------------------------------
1 #include <stdio.h>
2 int main(int argc, char const *argv[])
3 {
4 int temp1, temp2, isFirst = 1, haveOutput = 0;
5 while(1)
6 {
7 scanf("%d %d", &temp1, &temp2);
8 if(temp2 != 0)
9 {
10 if(isFirst == 1)
11 {
12 printf("%d %d", temp2 * temp1, temp2 - 1);
13 isFirst = 0;
14 }
15 else
16 printf(" %d %d", temp2 * temp1, temp2 - 1);
17 haveOutput = 1;
18 }
19 if(getchar() == '\n')
20 break;
21 }
22 if(!haveOutput) printf("0 0");
23 return 0;
24 }
来源:http://www.cnblogs.com/hello-lijj/p/7085634.html