Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Extreamly large numbers in C++


ghost's Avatar
0 0

I need to display a number in C++ that is 23+ characters( longer then a long double ) so how could I do this, I have heard of the linked list but i am not that advanced yet.:)


ynori7's Avatar
Future Emperor of Earth
0 0

you could make an array of numbers. how many significant figures do you need? cuz if it's a number like 123450000000000000000000000000 then you can just use scientific notation.


ghost's Avatar
0 0

#include <iostream>

main() { long long int ulli;
ulli = 317584931803000000000000000000ll; std::cout << ulli; std::cin.get(); return 0;
}

Hope that helps


ynori7's Avatar
Future Emperor of Earth
0 0

i dont remeber how to make a linked list in c++, but if you want i could explain the concept. actually my scheme 1 article touches on it a little when it gets into lists.


ghost's Avatar
0 0

Nope the long long was not long enough. I think i know what i am going to do, make a function that first solves the problem and then adds as may zeros until the number has the needed characters


ynori7's Avatar
Future Emperor of Earth
0 0

strings would probably be the easiest way to go. just append digits to the end of it.


ghost's Avatar
0 0

Yeah leaning strings now seems simple enough thanks


ghost's Avatar
0 0

long double, if i remember right, should be able to hold that many digits. strings word as well.

peace.


ghost's Avatar
0 0

A long double only can hold s many digits but not up to 23


ghost's Avatar
0 0

okay, havent worked in c++ for a long time.

did the strings work for you?

maybe an unsigned long long int?

[edit] hell, nevermind. dont listen to me :happy:[/edit]


ghost's Avatar
0 0

It turns out in c++ that the c long long int is now called in c++ an unsigned long int when i originally heard long long int i was confused about what everyone meant
i still have to lean more to write this program


ghost's Avatar
0 0

isn't float bigger than double???


ynori7's Avatar
Future Emperor of Earth
0 0

alka wrote: isn't float bigger than double???

floats are 32 bits, doubles are 64 bits


ghost's Avatar
0 0

This would probably be most primitive of all primitive linked lists.It misses some basic functionality too like delete but this way its a bit easier to understand.In this form you can use it only to store int values.Its singly linked,if you wont double you must add another pointer in class member.Next points to next member and the other would point to previous. Anyway i think it wont solve your problem (which is quite interesting to me)because every object is its own entity,every int inside is just an int.you can store numbers and make a very long list but it wont be one entity.You could do almost the same thing with the array of int but that way you again have only ints lined up for printing maybe but not to make any calculations on it as a whole. I cant figure out the string trick because i can store a number in the string but when i extract one from inside and assign it back to int i get its decimal value but cant get back to ascii. …………………………………………………………………………………….. #include <cstdlib> #include <iostream>

using namespace std;

class member{ public: member *next;

    int value;
    member(int x=0):value(x){cout&lt;&lt;&quot;created member: &quot;&lt;&lt;value&lt;&lt;endl;}  
    

};

class list{ public: member *head;

    list():head(NULL){cout&lt;&lt;endl&lt;&lt;&quot;created list with members:&quot;&lt;&lt;endl;}
    
    member put( member &x);
    
    void print();

}; member list::put(member &x){ member *tmp=head; head=&x; head->next=tmp;

    }

void list::print(){ member *tmp=head; while(tmp) { cout<<tmp->value<<"\t"; tmp=tmp->next; } cout<<endl; }

int main(int argc, char *argv[]) {
member q(2); member a(3); member z(4); list lst; lst.put(q); lst.put(a); lst.put(z); lst.print();

system(&quot;PAUSE&quot;);
return EXIT_SUCCESS;

}

……………………………………………………………………………………… Anyway an interesting problem…


ynori7's Avatar
Future Emperor of Earth
0 0

global1 wrote: This would probably be most primitive of all primitive linked lists.It misses some basic functionality too like delete but this way its a bit easier to understand.In this form you can use it only to store int values.Its singly linked,if you wont double you must add another pointer in class member.Next points to next member and the other would point to previous.

Anyway i think it wont solve your problem (which is quite interesting to me)because every object is its own entity,every int inside is just an int.you can store numbers and make a very long list but it wont be one entity.You could do almost the same thing with the array of int but that way you again have only ints lined up for printing maybe but not to make any calculations on it as a whole. I cant figure out the string trick because i can store a number in the string but when i extract one from inside and assign it back to int i get its decimal value but cant get back to ascii.

i think the problem was solved already and dont write the code for the guy. he wont learn if you do all the work for him.


ghost's Avatar
0 0

Happy 2008!!! So ok i wont.But why not? A Q4U:Is it better to let someone discover the hot watter or to help him understand why the water is hot?I personally more appreciate later approach. but anyway,i wont post this way again Thanx Bye


ynori7's Avatar
Future Emperor of Earth
0 0

global1 wrote: Happy 2008!!! So ok i wont.But why not? A Q4U:Is it better to let someone discover the hot watter or to help him understand why the water is hot?I personally more appreciate later approach. but anyway,i wont post this way again Thanx Bye

you're right that it's good to help people to understand things, but it is better if you only open the door for them rather than push them through it. just give suggestions and input unless someone asks for more detailed assistance. i dont mean to criticize, but to give a bit of wisdom.