0% found this document useful (0 votes)
57 views

Machine Project CS10-L: B2 TH / 12-4:30 P.M

This document describes a machine project to create a C++ program that can multiply two large numbers with up to 25 digits and output the result with infinite precision. The program takes in two numbers as input, calculates the product, and outputs the result. The design includes an algorithm, flowchart, source code, and examples of outputs for different inputs. Built-in functions and group contributions are also documented.

Uploaded by

romarking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Machine Project CS10-L: B2 TH / 12-4:30 P.M

This document describes a machine project to create a C++ program that can multiply two large numbers with up to 25 digits and output the result with infinite precision. The program takes in two numbers as input, calculates the product, and outputs the result. The design includes an algorithm, flowchart, source code, and examples of outputs for different inputs. Built-in functions and group contributions are also documented.

Uploaded by

romarking
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

MACHINE PROJECT

CS10-L
EXTREME MULTIPLICATION

Submitted by:
Catiltil, John Matthew C.
Celebre, Romar King D.
B2
TH / 12-4:30 P.M.

Submitted to:
Prof. Mideth B. Abisado
1st Q / 2013-2014

Table of Contents:

I.

Declaration of Originality of Work.

II.

Machine Project Description


a. Problem Statement

III.

Design
a. Algorithm
b. Flowchart
c. Source code
d. Output five sets of output, with different inputs

IV.

Built-n functions used

V.

References

VI.

Group contributions

I.

Declaration of Originality of Work

We hereby declare that this laboratory project entitled Extreme Multiplication


submitted as partial fulfilment of the requirements for the course CS10-L, is our own
unaided work and not copied from nor written in any collaboration with other person
or institution, and has not been formerly submitted to other university/ institution as
program requirement.

Catiltil, John Matthew C.


Name and Signature

Celebre, Romar King D.


Name and Signature

II.

Machine Project Description

a. Problem Statement
This project aims to make a c++ program that will be able to multiply
two large numbers with a maximum of 25-digits and give the result in an
infinite precision.
III.

Design
a. Algorithm
1.
2.
3.
4.
5.

Input the first number.


Input the second number.
Caculating the given inputs.
Output of the results.
End of th

b. Flowchart

START

END

INPUT 1ST
NUMBER

OUTPUT
(RESULT)

INPUT 2ND
NUMBER

MULTIPLYING
THE
NUMBERS

c. Source Code
#include<conio.h>
#include <iostream>
#include <string>
#define OVERFLOW 2
#define ROW b_len
#define COL a_len+b_len+OVERFLOW
using namespace std;
int getCarry(int num) {
int carry = 0;
if(num>=10) {
while(num!=0) {
carry = num %10;
num = num/10;
}
}
else carry = 0;
return carry;
}
int num(char a) {
return int(a)-48;
}
string mult(string a, string b) {
string ret;
int a_len = a.length();
int b_len = b.length();
int mat[ROW][COL];
for(int i =0; i<ROW; ++i) {
for(int j=0; j<COL; ++j) {
mat[i][j] = 0;
}
}
int carry=0, n,x=a_len-1,y=b_len-1;
for(int i=0; i<ROW; ++i) {
x=a_len-1;
carry = 0;
for(int j=(COL-1)-i; j>=0; --j) {
if((x>=0)&&(y>=0)) {
n = (num(a[x])*num(b[y]))+carry;

mat[i][j] = n%10;
carry = getCarry(n);
}
else if((x>=-1)&&(y>=-1)) mat[i][j] = carry;
x=x-1;
}
y=y-1;
}
carry = 0;
int sum_arr[COL];
for(int i =0; i<COL; ++i) sum_arr[i] = 0;
for(int i=0; i<ROW; ++i) {
for(int j=COL-1; j>=0; --j) {
sum_arr[j] += (mat[i][j]);
}
}
int temp;
for(int i=COL-1; i>=0; --i) {
sum_arr[i] += carry;
temp = sum_arr[i];
sum_arr[i] = sum_arr[i]%10;
carry = getCarry(temp);
}
for(int i=0; i<COL; ++i) {
ret.push_back(char(sum_arr[i]+48));
}
while(ret[0]=='0'){
ret = ret.substr(1,ret.length()-1);
}
return ret;
}
void printhuge(string a) {
cout<<"\n";
for(string::iterator i = a.begin(); i!=a.end(); ++i) {
cout<<*i;
}
}
int main() {
string a,b;
cout<<"Input your first number: ";
cin>>a;

cout<<"Input your second number: ";


cin>>b;
cout<<"\nThe product of these two large numbers is: ";
printhuge(mult(a,b));
getch();
return 0;
}

d. Outputs

IV.

Built-in Functions Used


Getch();

V.

References
C++ Programming:Problem Analysis to Program Design ( D.S. Malik)

VI.

Group Contributions

Member Name
Catiltil, John Matthew C.

Task
To do the codes for the
calculations

Celebre, Romar King D.

To do the codes for the


output

Module Programmed
int getCarry(int num)
int num(char a)
string mult(string a, string b)
void printhuge(string a)
int main()

You might also like