I have already asked for help a couple of times today and this is what happened. The program must perform raising to the power of long numbers. The number and degree are written in string. The problem - the construction seems to work, but randomly, in the literal sense of the word. With a degree greater than 10, sometimes it considers true, and sometimes incorrect values in general. For example, if a = 25 and n = 30, the program should output 867361737988403547205962240695953369140625, and displays 9607807733118534088134765625. With a = 2555555555 and n = 25, some characters and random numbers are displayed ... Crackers are output when entering a large base. For example, 132 ^ 1000 considers true. 13265563353646646453454 ^ 165 also thinks wrong, but if you take smaller values, everything is fine. I check with tungsten. I do not know where to start, I can’t establish the pattern of the problem at all. I ask for help, it is very necessary, it remains to finish quite a bit !!! Thank.
#include "stdafx.h" #include <string> #include <iostream> #include <climits> using namespace std; char A[100000000],B[100], C[10000000000]; long long int length; void DeleteNull(string &str){ int i = 0; while(str[i] == '0'|| str[i] < '0' || str [i] > '9') i++; str.erase(0,i); } void inc(string &s){ int l = s.length(); bool state = true; for(int i = l-1; state && i >= 0; --i) { if (state) s[i]++; if (state = (s[i] > '9')) s[i] = '0'; } if (state) s = '1' + s; } void Umnoj(string &a, string &temp, int size){ temp=""; for (int ix = 0; ix < length+100; ix++){ C[ix] = 0; A[ix] = 0; } for (int i=0; i<a.size(); i++) A[i]=a[a.size()-i-1]-'0'; length += size+1; for (int ix = 0; ix < a.size(); ix++) for (int jx = 0; jx < size; jx++) C[ix + jx] += A[ix] * B[jx]; for (int ix = 0; ix < length-1; ix++) { C[ix + 1] += C[ix] / 10; C[ix] %= 10; } while (C[length] == 0) length-- ; for(int i=length; i>-1; i--) temp+=C[i]+'0';//перевод числа в string DeleteNull(temp);//удаление всякого мусора перед числом a=temp; } int main() { string a,n,t,count="1",temp; int size; // cin>>a; // cin>>n; a="13444645";//основание n="30";//степень size=a.size(); temp=a; length=size; for (int i=0; i<size; i++) B[i]=a[a.size()-i-1]-'0'; while(n.compare(count)!=0){ inc(count); Umnoj(a,temp,size); } cout<<a<<endl; system("PAUSE"); }