Write a program that allows the user to enter two positive integers and outputs
ID: 3777142 • Letter: W
Question
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds simple? Here's the catch: The numbers may be any size! They may be way too large to store in a single variable. You may not assume any particular maximum number of digits. Here are two sample runs: Enter first positive integer: 87435704325782438757285045089847 Enter second positive integer: 4523852345234255895 Sum = 87435704325786962609630279345742 Enter first positive integer: 99999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999999999999999999999999999 99999999999999999999999999999999999999999999999 Enter second positive integer: 1 Sum = 10000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000 Your homework will be graded out of 100 points with the following breakdown: Correctness: You should follow all instructions exactly as stated above. 70 points. Elegance and Efficiency: You should use the concepts we have learned in class to write simple, elegant code. Use functions to structure your program in a well thought out manner. 20 points. Format: Your code should use indentation and other spacing that makes the code readable and easy to understand. 5 points. Comments: You should include one comment at the top of the program explaining what it does, one at the top of every function you write, and some within the code explaining how things work whenever it isn't obvious. 5 points.
Explanation / Answer
You can use signed long long data type to store the values , it gives you enough space to hold very very large numbers;
#include<conio.h>
#include<stdio.h>
void main()
{ signed long long a,b,sum;
cout<<"Enter the first number"<<endl;
cin>>a;
cout<<"Enter the second number"<<endl;
cin>>b;
sum = a+b;
cout<<"Sum of the numbers is "<<sum<<endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.