MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Wednesday, March 13, 2013

uva solve problem 424 - Integer Inquiry

#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,k,l,la,lb,m,h,p,r,d;
    char a[1000],b[1000],c[1000],s[1000];
    lb=1;
    c[0]=48;
       for(i=1;i<=100;i++)
        {
            d=0;
            scanf("%s",a);
            if(a[d]==48)
            break;
            la=strlen(a);
            j=0;
            for(i=la-1;i>=0;i--)
            {
                b[j++]=a[i];

            }
            h=0;
            l=la;
            if(l<lb)
            l=lb;
            for(k=0;k<l;k++)
            {
                if(la>k)
                b[k]=b[k]-48;
                else
                b[k]=0;
                if(lb>k)
                c[k]=c[k]-48;
                else
                c[k]=0;
                p=b[k]+c[k]+h;
                s[k]=p%10+48;
                h=p/10;

            }
            s[k]=48;
            if(h>0)
            s[k++]=h+48;
            for(r=0;r<k;r++)
            c[r]=s[r];
            l=r;
            lb=l;
        }
        for(m=r-1;m>=0;m--)
        printf("%c",c[m]);
        printf("\n");
    return 0;
}

No comments:

Post a Comment