Calculation results with very long numbers
Hi. I am new to C++.
Learning from tutorials.
One of tutorials shows how to write a simple program that accepts a number and then calculates it to power of another user specified number. Simple numbers work fine (2^5=25, etc) But I want to try very long numbers (1234567^34854322).
The program either quits after accepting the two numbers, or shows something like 1.#INF.
I realize the result may take a hundred lines to display, that is fine.
Question. Is this a failure to calculate or failure to display a result that has been calculated?
How do I format the result so it can be seen?
What are the limitations, if any?
Here is the program:
Code:
// Compute power of a number
#include <iostream>
#include <cmath>
#include <iomanip>
int main()
{
using namespace std;
double power1;
double num1;
cout << "Enter number" << endl;
cin >> num1;
cout << "Enter power" << endl;
cin >> power1;
num1 = pow(power1,num1);
cout << setprecision(130) << num1 << endl;
system("pause");
return 0;
}
What is the best source to look up these custom datatypes?
Syscal, thank you for the reply.
What is the best source to look up these custom vector data types? Is this the right term, first of all?
Thanks again.
How to connect these two codes?
I found an example of how to use vectors, but this example below uses a constraint. How do I connect the two so it stores long numbers as shown above:
Code:
#include <cstring> // memcpy
#include <vector>
#include <cstdio> // printf
int main()
{
using namespace std;
const char arr[] = "12345678902333333333323323333333345345345345345345435";
// construct a vector with 11 zero-initialized chars.
vector<char> vec(sizeof arr);
// copy 11 chars from arr into the vector
memcpy(&vec[0], arr, sizeof arr);
// prints "1234567890"
printf("%s", &vec[0]);
system("pause");
return 0;
}