Adding loop?

adding 2 numbers of 20 digits

Page 1 of 1

1 Replies - 800 Views - Last Post: 11 September 2007 - 05:58 PM Rate Topic: -----

#1 bortiz0823  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-January 07

Adding loop?

Posted 11 September 2007 - 05:57 PM

hi guys, I have already the conversion of CHAR to INT. I made the code to show the 2 numbers of 20 digits, but I have no idea how can I add this two numbers. I have to use a loop?? Here is the code and any idea are welcome.
//Solo muestra mis 2 numeros de 20 digitos
//Solo falta sumarlos

#include <iostream>
#include <cstdlib>
using namespace std;


int Sum(char A[20])
{
	 char aa;
	 int num1[ 20 ];
	 
	 for( int ii = 0; ii < 20; ii++ )
   {
	 aa = A[ ii ]; //Conversion
	 num1[ ii ] = atoi( &aa ); //Conversion
   }   
	 cout << "\n\n ";
	 for( int ii = 0; ii < 20; ii++ )
   {
	 cout << num1[ ii ];
	
   } 
   
}

int Sum2(char B[20])
{
	 char bb;
	 int num2[ 20 ];
	 
	 for( int ii = 0; ii < 20; ii++ )
   {
	 bb = B[ ii ]; //Conversion
	 num2[ ii ] = atoi( &bb ); //Conversion

   }  
	 cout << "\n+";
	 for( int ii = 0; ii < 20; ii++ )
   {
	 cout << num2[ ii ];
	  
   }
   cout<<"\n---------------------\n";
} 
  
int main()
{

   char numA[ 20 ];
   char numB[ 20 ];
   
   cout<<"Entre un numero de 20 digitos: ";
   cin>>numA;
   cout<<"\nEntre otro numero de 20 digitos: ";
   cin>>numB;
   Sum(numA);
   Sum2(numB);
   
   
   cout<<"\n";
   system("pause");
   return 0;

}



Is This A Good Question/Topic? 0
  • +

Replies To: Adding loop?

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,283
  • Joined: 17-March 01

Re: Adding loop?

Posted 11 September 2007 - 05:58 PM

Is this any different than your other thread on the same topic?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1