রবিবার, ২৮ আগস্ট, ২০১৬

UVA 713 - Adding Reversed Numbers

#include<stdio.h>
#include<string.h>
main()
{
long int tst,cas;
scanf("%ld",&cas);
for(tst=1;tst<=cas;tst++)
{
char a[100000]={0},s[100000]={0};
long b[100000]={0},c[100000]={0};
scanf("%s%s",a,s);
{
long l1=strlen(a);
long l2=strlen(s);

if(l2>l1)
{
l1=l2;
}
long i,j,k,dif,i1=0,j1=0,carry=0,s1,a1;
for(i=0;i<l1;i++)
{
//printf("%c %c ",a[i],s[i]);
if(a[i]=='\0')
{
a1=0;
}
else
a1=a[i]-48;
if(s[i]=='\0')
{
s1=0;
}
else
{
s1=s[i]-48;
}

long c=a1+s1+carry;
if(c>9)
{
carry=1;
}
else
carry=0;
//printf("%ld\n%ld\n",c,carry);
b[i1++]=c%10;
//printf("%ld ",b[i1-1]);
}
if(carry!=0)
{
b[i1++]=1;
}
long flag=0,flag1=0;
long t=0;
while(b[t]==0)
t++;
for(i=t;i<i1;i++)
{
printf("%ld",b[i]);
}
printf("\n");
}
}
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...