Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Submission Guideline You must follow this guideline! Your submission will be marked automatically. Failure to follow this guideline will result in 0. Your submission should

Submission Guideline

You must follow this guideline! Your submission will be marked automatically. Failure to

follow this guideline will result in 0.

Your submission should contain exactly one file:

main.cpp

. You do not need to submit a design.

Your program takes one line as input. The input line contains three integers separated by spaces. Let

the three integers be I1, I2, and B. I1 and I2 are both nonnegative integers up to 100 digits long (there are

no leading 0s, except when the value itself is 0). B is I1 and I2s base (B is from 2 to 10).

1

Your program should output the sum of I1 and I2, using the school method, then the product of I1 and

I2, using the Karatsuba algorithm, and finally the ratio between I1 and I2 (rounded down). You are asked

to come up with a way to perform this division. Its not covered in lectures. I2 will not be 0.

The results should still use base B. Please separate the results using one space.

Sample input 1: 101 5 10

Sample output 1: 106 505 20

Sample input 2: 10 111 2

Sample output 2: 1001 1110 0

Sample input 3: 111 10 2

Sample output 2: 1001 1110 11

here is what suppose to do when mark will get

For input 11100111101110001110000000010010011100110011001110000111100011110110110001010000100 111100000011110000101101 2 Output received Enter I1, I2 and B: Output shouldbe 11100111101110001110000000010010011100110011001110000111101011010111001111010110001 11011001011100111100101000100001010011111011011010001101011010100100100111111101000100001110100000100110100 11110110111011011010111111110100101110011000001000101011001 For input 451710053133256677641251311040226202326227045005325205103122312 4516571706445517636723600401754640024213675365546 8 Output received Enter I1, I2 and B: Output shouldbe 451710053133263416433157756560065126126631021645351421000510060 2552243562140011401532646724217051153537454152360561035761647043014346722502103144202523222512076347532750213174 100005255607652 For input 220120202110220201020111002201122122102201101222210221011220001121220201200200200000020101121122212 2200021111000221021022110100112202100 3 Output received Enter I1, I2 and B: Output shouldbe 220120202110220201020111002201122122102201101222210221011220011022012012201121221022200202011102012 2102210211120012010011221001210021000211000110210122222121000121122021210202001210012012001222022012222212100022101200121210210200222200 100011221210012022211201111012120112111010120210220111201222110 

here is the code :

#include

using namespace std;

long long int exp(long long int a, long long int b){

long long int res = 1;

for(int i=0; i

res *= a;

return res;

}

long long int convert_dec(long long int n, long long int b){

long long int i=0;

long long int s = 0; //loop for converting whatever-base integer into decimal //the step for this is : //First to regards the number of decimal type----is to verify the digits of the input number //Second is to use the formula as newN=Cn-1*an-1+...+c0*a0; //Finally return value of s while(n>0){

s += (n%10) * exp(b, i);

n = n/10;

i++;

}

return s;

}

long long int convert(long long int n,long long int b){

int i=1;

long long int s = 0; //loop for return the number into the seting base which can be seen in the inour number //the convert steps similar for changing the number into decimal numbers

while(n>0){

s += (n%b) * i;

n = n/b;

i *=10;

}

return s;

} //Functions implement

int main() {

long long int I1, I2, B, C_I1 = 0, C_I2 = 0;

cout<<"Enter I1, I2 and B: ";

cin>>I1>>I2>>B;

C_I1 = convert_dec(I1, B);

C_I2 = convert_dec(I2, B);

cout<<"Output: ";

cout<

return 0;

}

but when i compile it , it told me that "Floating point exception (core dumped)"

How to fix it ?

I am new for c++,looking forward a detaiked guide,

Many thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago