Monday, April 14, 2014

large number adition using linked list C++

#include<iostream>
#include<cstdlib>
using namespace std;
struct node
{
int data;
node *next;
};
int main()
{
int a2[10],m=0,n=0,a1[10],y=0,r1[10],r2[10],i=0,j=0;
char c1[10],c2[10],b;
node *l1,*l2,*s1,*s2;
cout<<"enter 1st number";
cin.getline(c1,10);
while(c1[i]!='\0')
{
a1[i]=c1[i]-48;
i++;m++;
}
cout<<"\n enter 2nd number";
cin.getline(c2,10);
while(c2[j]!='\0')
{
a2[j]=c2[j]-48;
j++;n++; }
for(i=0;i<m;i++)
cout<<a1[i];
s1=l1;
for(j=m-1;j>0;j--)
{
cout<<"hi";
l1=new node;
l1->data=a1[m-j-1];
l1=l1->next;
}
l1->next=NULL;
l1=s1;
s2=l2;
for(i=n;i>0;i--)
{
l2=new node;
l2->data=a2[n-i];
l2=l2->next;
}
l2->next=NULL;
l2=s2;
cout<<"________+++++++";
while(l1!=NULL)
{
cout<<l1->data;
l1=l1->next;
}}

No comments:

Post a Comment

Contributors

Translate