# Thread: multiply arbitrarily large real numbers

1. ## multiply arbitrarily large real numbers

Please, Help me with my project.

Write a program that will multiply arbitrarily large real numbers (stored in the chain). Numbers can be positive or negative and the program will accept a comma as decimal point.
Example output:
15321548949451231684.12654894856 x 15,658,213,548,949.5684516 =239908085351191302633721198032836,254474415727249 696

Classic calculator Is not problem for me, but this program is too hard for me.
So anyone who know how I can do this please help. Thank you

2. There's certainly no built-in mechanism, so you'll have to (1) pick an algorithm for multiplying numbers together and then (2) implement it for the data structure you are using (I'm assuming "chain" refers to a linked list.) That assumes you've already done (3) input and (4) output.

3. If you had sufficient time and a large enough piece of paper, could you solve the problem on paper? (assuming you never got bored and never made mistakes)
If so, all you need to do is follow the "algorithm" you used to do is and then translate that algorithm into pseudocode and then finally into C code.
Can you read in a large number character by character into the "chain" (I assume this is a linked list)?
Which parts do you find hard and what have you done so far?

4. sorry for translate mistake. I mean string, not chain (In czech language nearly same words)
I have this program:
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>

double string2double(char *s)

{

double d;

char *p = strchr(s, ','), *end;

if (p) *p = '.';

d = strtod(s, &end);

if (*end != 0) d = 0;

return d;

}

int main(int argc, char * argv[])

{

char s1[1000], s2[1000], s3[1000];
char rep;
double d1, d2, d3;

do{
scanf("%s\n",s1);
scanf("%s",s2);

setlocale(LC_NUMERIC, "C");

d1 = string2double(s1);

d2 = string2double(s2);

d3=d1*d2;

d3=sprintf (s3, "%d * %d = %d", d1, d2, d3);
printf ("%s",s3);

printf("\n\n Repeat? y/n:");

scanf("\n%c", &rep);

printf("\n");

}while(rep=='y' || rep=='Y');

return 0;

}```
I need make d3(double) to s3(string) with a large total number of cells (like in example output )

5. The catch is that it is physically impossible to make d3 into s3 with a large total number of cells. Doubles store their contents in a scientific-notation-y number-plus-exponent fashion, so you will only ever get 18 or so digits back (it's 53 bits if I recall correctly). If you want more you're going to have to work a lot harder. (Maybe a linked list is actually in your future after all.)

Also your string2double function would fail so hard on the sample input -- those commas are thousands separators, not decimal points.

6. Well, few years ago I had to do something similar and the problem is a bit more complicated than it seems at first. If we put the issue with the decimal point to the side, for "arbitrarily large real numbers" you can use LibTom for example. I used LibTomMath for very long integer values and it took some time to grasp the whole thing, but in the end everything just worked as it should.

I actually bought a book to learn how to use the library and wrote several functions on my own to simplify everything as it is rather complex.

7. I doubt the solution to the stated problem is to find a library. Unfortunately too many people here suggest libraries as opposed to letting the student develop their own solutions, which was undoubtedly the point of the exercise. You don't learn anything by linking some package.

8. Step 1. Figure out how to add arbitrarily large integer numbers.
Step 2. Figure out how to multiply arbitrarily large integer numbers.
Step 3. Figure out how to add arbitrarily large real numbers.
Step 4. Figure out how to multiply arbitrarily large real numbers.

Tim S.

Popular pages Recent additions