标签:
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stdlib.h> #include<string.h> //C语言声明变量需要加上stuct //C语言结构内部不可以有函数 //C语言结构体没有公有,私有,继承 struct MyStruct { int num1; int num2; }; struct MyStruct MyStruct1; /// 加法,减法 /// 1234.567 ×12345.987 /// 15K+ 除法, //———————— void getbigdata(char *dataa,char* datab) { int lengtha = strlen(dataa); int lengthb = strlen(datab); int *pres = (int *)malloc(sizeof(int)*(lengtha + lengthb)); memset(pres, 0, sizeof(int)*(lengtha + lengthb));//初始化 //累乘 for (int i = 0; i < lengtha;i++) { for (int j = 0; j < lengthb;j++) { pres[i+j+1]+=(dataa[i] - ‘0‘)*(datab[j] - ‘0‘); } } //进位 for (int i = lengtha + lengthb-1;i>=0;i--) { if (pres[i]>=10)//进位 { pres[i - 1] += pres[i] / 10;//进位 pres[i] %= 10;//取出个位数 } } int i = 0; while (pres[i]==0) { i++;//恰好不为0的位置 } char *lastres = malloc(sizeof(char)*(lengtha + lengthb)); int j; for (j = 0; j < lengtha + lengthb; j++, i++) { lastres[j] = pres[i] + ‘0‘; } lastres[j] = ‘\0‘; printf("last结果=%s",lastres); } void main() { char str1[100] = { 0 }; char str2[100] = { 0 }; scanf("%s%s", str1, str2); printf("str1=%s,str2=%s", str1, str2);//打印结果 getbigdata(str1, str2); //strcpy(str1, "123123"); system("pause"); }
标签:
原文地址:http://www.cnblogs.com/zhuyaguang/p/4884656.html