Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter




Source code


Posted Date: 12 May 2008      Total Responses: 2

Posted By: CONFIDENCE IS THE COMPANION OF SUCCESS       Member Level: Diamond     Points: 1


Add two long positive intergers

include the header files

struct node
{
int data;
struct node*next;
};
void insert(struct node**p,int num)
{
struct node*temp;
if(*p==NULL)
{
(*p)=(struct node*)malloc(sizeof(struct node));
(*p)->next=NULL;
(*p)->data=num;
}
else
{
temp=(struct node*)malloc(sizeof(struct node));
temp->next=(*p);
(*p)=temp;
(*p)->data=num;
}
}


void add_in(struct node*a,struct node*b,struct node**c)
{
int d,carry;
carry=0;
struct node*t;
while(a!=NULL&&b!=NULL)
{
d=(a->data+b->data+carry)%10;
insert(c,d);
if( (a->data+b->data+carry) >= 10)
{
carry=1;
}
else carry=0;
a=a->next;
b=b->next;
}
if(a==NULL&&b==NULL)
{
return;
}
else
{
if(a!=NULL&&b==NULL)
{
t=a;
}
else
{
t=b;
}
while(t!=NULL)
{
d=(carry+t->data)%10;
if((carry+t->data)>=10)
carry=1;
else
carry=0;
insert(c,d);
t=t->next;
}
if(carry==1)
insert(c,carry);
}
}
void numin(struct node**p)
{
*p=NULL;char c='c';
while(c!='n')
{
c=getch();
if(!isdigit(c))
return;
else
{
putch(c);
insert(p,c-'0');
}
}
}
void disp(struct node*p)
{
if(p==NULL)
return;
else
{
printf("%d",p->data);
disp(p->next);
}

}
void main()
{
struct node *a,*b,*c;
clrscr();
a=b=c=NULL;
printf("Enter the first number....");
numin(&a);
printf("Enter the second number....");
numin(&b);
printf("The added result is...");
add_in(a,b,&c);
disp(c);
getch();
}




Responses

Author: kondapalli    12 May 2008Member Level: GoldRating:     Points: 2
Hi friend nice programe if u want more source codes visit www.cheaven.blogspot.com


Author: Nirmal P    14 May 2008Member Level: SilverRating:     Points: 2
Nice one but we don't really need codes for adding two numbers. There are already library functions to do that


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Top 10 Best Practices for Building a Large Scale Relational Data Warehouse
Previous : How to Quit Smoke - TIPS
Return to Discussion Forum
Post New Message
Category: General

Related Messages

Watch TV Channels



Contact Us    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.