You are here:

- Home
- Computing/Technology
- C/C++
- C++
- logic for algebraic operation of large number

Advertisement

I have got an end semester project in c++. In this project we have to write the program to add, subtract ,multiply,divide, square root, and square the very very large number. for example 1234987654567891234509876+12343231678676554348999862743874= ?

Hello Nischay, thank you for the question.

In C++, the largest number you can add is UINT_MAX, which has a value of 4 billion and some. If you conform your numbers to that, you would do something like this:

unsigned int first, second, operation;

cout << "Enter the first number: ";

cin >> first;

cout << "Enter the second number: ";

cin >> second;

cout << "1. Add 2. Subtract 3. Multiply 4. Divide";

cin >> operation;

if(operation == 1)

{

cout << "The result is: " << first + second;

}

else if(operation == 2)

{

cout << "The result is: " << first - second;

}

else if(operation == 3)

{

cout << "The result is: " << first * second;

}

else if(operation == 4)

{

cout << "The result is: " << first / second;

}

else

{

cout << "Invalid operation";

}

You would simply wrap that into a while loop until the user hit a certain key to quit.

I hope this information was helpful.

- Eddie

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.