New Member FAQ | Forums | Earn Revenue


Resources Entrance Ask Experts Exam Papers Jobs English Projects Universities Colleges Courses Schools Training My India



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



Adding Huge Numbers in C


Posted Date:     Total Responses: 0    Posted By: RAGESH V R   Member Level: Gold   Points/Cash: 4   


We know that integer variable can hold a value between -32768 to +32767. So what we will do if we are using a huge value? Then may we will use long qualifier. But the size of the long int is 4 bytes. So what we will do if the number to be added is larger than a value that a long int can accommodate. Then we will use string addition. Store the numbers into a character array and add each digits.




#include
#include
#include
void main()
{
char a[20],b[20],r[21]={""};
int re,c=0,la,lb,i,j,diff=0,l;
printf("Enter 1st No. : ");
gets(a);
printf("Enter 2nd No. : ");
gets(b);
la=strlen(a);
lb=strlen(b);
diff=la-lb;
if(diff<0)
{
diff=-diff;
strrev(a);
for(i=0;i strcat(a,"0");
strrev(a);
}
else
{
strrev(b);
for(i=0;i strcat(b,"0");
strrev(b);
}
printf("%s\n",a);
printf("%s\n",b);
l=strlen(a);
for(i=l-1,j=0;i>=0;i--,j++)
{
re=a[i]-48+b[i]-48+c;
c=re/10;
re=re%10;
r[j]=re+48;
}
if(c>0)
{
r[j++]=c+48;
}
r[j]='\0';
strrev(r);
printf("Sum : %s\n\n",r);
getch();
}


Project Feedbacks


No feedbacks found. Be the first to respond and make money from revenue sharing program.

Post Feedback
You must Sign In to post a feedback.
Next Project: Selection Sort Program - Java
Previous Project: Oracle Label Security -Best Practices for Government and Defense Applications

Return to Project Index

Post New Project


Related Projects



Advertise Here





Contact Us   Advertise   Editors    Privacy Policy    Terms Of Use   

ISC Technologies.
2006 - 2009 All Rights Reserved.