Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- using namespace std;
- string pow(unsigned int x, unsigned int y,unsigned int memsize)
- {
- unsigned char *memory = (char*)malloc(memsize);
- memset(&memory[0], 0, memsize);
- memory[0] = 1;
- string pow;char buf[2];
- bool zeros=true;
- int i, in;
- for (i =0; i<y; i++)
- {
- for (in=0; in<y; in++)
- memory[in]*=x;
- for (in=0; in<y-1; in++)
- if(memory[in]>9)
- {
- memory[in+1] += memory[in]/10;
- memory[in] %=10;
- }
- }
- for (i=y-1; i>=0; i--)
- {
- if (zeros) if (memory[i] == 0) continue;
- else {
- in = i;
- zeros = false;
- }
- itoa(memory[i], &buf[0], 10);
- pow+=buf;
- }
- free(memory);
- return pow;
- }
- int main()
- {
- int x = 1, y;
- cout<<"x^y"<<endl;
- while (x)
- {
- cout<<"x: "; cin>>x;
- cout<<"y: "; cin>>y;
- string result = pow(x,y,8000);
- cout<<result<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment