日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

小数精确相乘

發布時間:2024/5/14 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小数精确相乘 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <iostream> #include <cassert> using namespace std;void PrintMulNum(char *numA,int alen,char *numB,int blen) {if (NULL == numA || NULL == numB || alen <=0 || blen <=0){return;}int *num1 = new int[alen-1];//減去小數點1位assert(num1 != NULL);int *num2 = new int[blen-1];assert(num2!=NULL);int *result = new int[(alen-1)*(blen-1)+1];assert(result != NULL);memset(result,0,((alen-1)*(blen-1)+1)*sizeof(int));int i,j,pointCountA=0,pointCountB=0,posA,posB;for (i=0,j=0; j < alen;j++){if (numA[alen-1-j]!='.'){pointCountA++;num1[i]=numA[alen-1-j]-'0';cout << "---"<<i<<"---"<<num1[i]<<endl;i++;}else{posA = pointCountA;//計算小數點位置}}for (i=0,j=0; j < blen;j++){if (numB[blen-1-j]!='.'){pointCountB++;num2[i]=numB[blen-1-j]-'0';cout << "---"<<i<<"---"<<num2[i]<<endl;i++;}else{posB = pointCountB;}}int point = posA+posB;//計算result中小數點位置for (i=0; i < alen-1; ++i){for (j=0;j<blen-1;++j){result[i+j] +=num1[i]*num2[j];cout << "---"<<i+j<<"---"<<result[i+j]<<endl;}}for (i=0;i < (alen-1)*(blen-1);i++){if (result[i] > 9){result[i+1] += result[i]/10;result[i] %=10; }cout << "---"<<i<<"---"<<result[i]<<endl;}bool flag = true;for (i=(alen-1)*(blen-1);i>=0;--i){if (result[i]==0&&flag){continue;}else{if (i ==point){cout <<result[i]<<".";}elsecout << result[i];flag=false;}}delete[] num1;delete[] num2;delete[] result;return;}int main() {char *n="1.243";char *m="3.241555";PrintMulNum(n,strlen(n),m,strlen(m)); }

總結

以上是生活随笔為你收集整理的小数精确相乘的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。