C語言 高精度減法__C語言

來源:互聯網
上載者:User
#include <stdio.h>  #include <string.h>    int main()  {      char m[555],n[555];      int i,len_m,len_n;      int a[555]={0},b[555]={0};      scanf("%s",m);      len_m =strlen(m);      for(i=0;i<=len_m -1;i++)          a[i]=m[len_m -1 -i]-'0';      scanf("%s",n);      len_n=strlen(n);      for(i=0;i<=len_n -1;i++)          b[i]=n[len_n -1 -i]-'0';      if(len_m < len_n)          {           printf("-");          for(i=0;i<len_n;i++)          {              b[i]-=a[i];              if(b[i]<0)              {                  b[i]+=10;                  b[i+1]--;              }          }          i=len_n-1;          while(b[i]==0)  i--;           for(;i>=0;i--)              printf("%d",b[i]);      }      else      {          for(i=0;i<len_m;i++)          {              a[i]-=b[i];              if(a[i]<0)              {                  a[i]+=10;                  a[i+1]--;              }          }          i=len_m-1;          while(a[i]==0)  i--;           for(;i>=0;i--)              printf("%d",a[i]);      }      return 0;  }  

—————————————————————————————————

本文原創自Slience的csdn技術部落格。

本部落格所有原創文章請以連結形式註明出處。

歡迎關注本技術部落格,本部落格的文章會不定期更新。


大多數人想要改造這個世界,但卻罕有人想改造自己。

世上沒有絕望的處境,只有對處境絕望的人。

                                              ————By slience

—————————————————————————————————

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.