zoukankan      html  css  js  c++  java
  • 5-16 一元多项式求导 (20分)

    设计函数求一元多项式的导数。

    输入格式:

    以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。

    输出格式:

    以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。

    输入样例:

    3 4 -5 2 6 1 -2 0
    

    输出样例:

    12 3 -10 1 6 0



    -------------------------------------------------------------------------
    注意两个情况:
    1、常数的求导为特例情况,输出 0 0
    2、当输入的指数不含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() == '
    ')
    20             break;
    21     }
    22     if(!haveOutput) printf("0 0");
    23     return 0;
    24 }
     
  • 相关阅读:
    iptables和DNS
    centos6.5下载
    linux 系统版本信息
    如何挂载
    Linux网络命令
    端口网络等
    linux安装tomcat
    ip设置
    最全DOS的CMD命令,程序员必会
    c语言文件分割与合并
  • 原文地址:https://www.cnblogs.com/hello-lijj/p/7085634.html
Copyright © 2011-2022 走看看