0

i want to assign a integer of 100 digit length to a object. like

class hugeint
{
///
};
void main()
{
hugeint a,b,c;
a=10000000000000000000000000000000....100;
b=20;
c=a+b;

}

can any buddy suggest me any simple idea to achieve this..

5
Contributors
9
Replies
10
Views
6 Years
Discussion Span
Last Post by pixelerator
0

Assign it to a std::string or char array. Within your class you can design your own methods for doing operations with the numbers.

0

Assign it to a std::string or char array. Within your class you can design your own methods for doing operations with the numbers.

yes i know we can do it int that way.i am newbie in c++ can you give me example snippet :)

0

Try it out for yourself first. Adding is probably the simplest you just have to manage the carries.

0

Try it out for yourself first. Adding is probably the simplest you just have to manage the carries.

i m trying :)

0

Post down the code which you have already worked on .. And then ask for specific questions. You get lots of help on this forum in that manner :)

0

i used the atoi function to convert the chacter array into the number

#include<iostream.h>
#include<conio.h>
void main()
{

char take[100];
int tnt[100];
int i;
clrscr();
i=0;
for(i=0;i<100;i++)
  {
  cin>>take[i];
  }

for(i=0;i<100;1++)
   {
tnt[i]=atoi(take[i]);

 }

but it didnt work..
if get all the chachter number into integer array i will go ahead but i am stucked in this !!
getch();
}

Edited by WaltP: Added CODE Tags

0

If you have a single chr that is a digit then converting it to a number is easy

char achar = '5';
int theint = achar - '0'; // theint now has the value 5

If necessary validate that the char is a digit using isdigit

0

#include<iostream.h> -- old, do not use
The current header (as of the 1990's) is simply iostream #include<conio.h> -- Non-portable, not standard, do not use void main() -- main() is an int function, not a void. See this clrscr(); -- Non-portable, not standard, do not use tnt[i]=atoi(take[i]); -- Does atoi() take a single character? Look it up.

If the character is >= '0' and <= '9', it's a digit. To convert a digit to a number, subtract '0'. Each of these character are just special numbers so you can do math on them.

0

Thank you both of :)
it is very helpful now i am go ahead.if i will stucked in another problem i will ask you :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.