#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[21],str2[21];
int i,j,a[20],b[20];
int add[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
printf("\n Enter number 1:");
for(i=0; i<21; i++)
{
str1[i]=getchar();
}
printf("\n Enter number 2:");
for(i=0; i<21; i++)
{
str2[i]=getchar();
}
//converting char to integer
for(i=0; i<20; i++)
{
a[i]=(int)str1[i]-48;
b[i]=(int)str2[i]-48;
}
printf("\n Print Number 1:");
for(i=0; i<20; i++)
{
printf("%d",a[i]);
}
printf("\n Print Number 2:");
for(i=0; i<20; i++)
{
printf("%d",b[i]);
}
for(i=20; i>-1;i--)
{
j= a[i]+b[i];
if(j<10)
{
add[i] +=j;
}
else
{
add[i]+=(j-10);
add[i-1]+=1;
}
}
printf("\n Print Addition:");
for(i=0; i<20; i++)
{
printf("%d",add[i]);
}
getch();
}
0 comments:
Post a Comment
Let us know your responses and feedback