Write a program in C language for addition of two numbers which have at least 20 digits each – IGNOU MCA Assignment 2015 – 16

By | September 24, 2015

MASTER OF COMPUTER APPLICATIONS

Course Code : MCSL-025
Course Title : Lab Course
Assignment Number : MCA(II)/L-025/Assignment/15-16
Maximum Marks : 50
Weightage : 25%
Write a program in C language for addition of two numbers which have at least 20 digits each.

 

#include<stdio.h>
void main()
{
int I,J,NUM1[20],NUM2[20],RES[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char N1[21],N2[21];/*getchar is excepts NewLIne charter also*/
clrscr();
printf(“\nENTER FIRST 20 DIGIT NUMBER : “);
for(I=0;I<21;I++)
{
N1[I]=getchar();
}
printf(“\nENTER SECOND 20 DIGIT NUMBER : “);
for(I=0;I<21;I++)
{
N2[I]=getchar();
}

for(I=0;I<20;I++)
{
NUM1[I]=(int)N1[I]-48;
NUM2[I]=(int)N2[I]-48;
}

printf(“\n\nENTER FIRST NUMBER IS : “);
for(I=0;I<20;I++)
{
printf(“%d”,NUM1[I]);
}
printf(“\n\nENTER SECOND NUMBER IS : “);
for(I=0;I<20;I++)
{
printf(“%d”,NUM2[I]);
}

for(I=19;I>-1;I–)
{
J=NUM1[I]+NUM2[I];
if(J<10)
RES[I+1]+=J;
else
{
RES[I+1]+=(J-10);
RES[I]+=1;
}
}

printf(“\n\n\nADDITION OF 2 NUMBERS IS : “);
for(I=0;I<21;I++)
{
printf(“%d”,RES[I]);
}
getch();
}

Program Code:

#include<stdio.h>
void main()
{
int I,J,NUM1[20],NUM2[20],RES[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char N1[21],N2[21];/*getchar is excepts NewLIne charter also*/
clrscr();
printf("\nENTER FIRST 20 DIGIT NUMBER : ");
for(I=0;I<21;I++)
{
N1[I]=getchar();
}
printf("\nENTER SECOND 20 DIGIT NUMBER : ");
for(I=0;I<21;I++)
{
N2[I]=getchar();
}
for(I=0;I<20;I++)
{
NUM1[I]=(int)N1[I]-48;
NUM2[I]=(int)N2[I]-48;
}
printf("\n\nENTER FIRST NUMBER IS : ");
for(I=0;I<20;I++)
{
printf("%d",NUM1[I]);
}
printf("\n\nENTER SECOND NUMBER IS : ");
for(I=0;I<20;I++)
{
printf("%d",NUM2[I]);
}
for(I=19;I>-1;I--)
{
J=NUM1[I]+NUM2[I];
if(J<10)
RES[I+1]+=J;
else
{
RES[I+1]+=(J-10);
RES[I]+=1;
}
}
printf("\n\n\nADDITION OF 2 NUMBERS IS : ");
for(I=0;I<21;I++)
{
printf("%d",RES[I]);
}
getch();
}

Screen Shots:

 C_program_Add_20_Digit_Numbers

C_program_Add_20_Digit_Numbers_Output