Character Value Summation

#include<stdio.h>
#include<string.h>
int main()
{
    char a[15], b[15], c[20];
    int n, m, i, j, k, x, y = 0;

    printf("Enter First Number : ");
    gets(a);

    printf("Enter Second Number : ");
    gets(b);

    n = strlen(a);
    m = strlen(b);

    i = n-1;
    j = m-1;

    if(n>m)
    {
        k = n;
    }
    else
        k = m;

    c[k] = '\0';
    k--;

    while(i>=0 && j>=0)
    {
        x = (a[i] - 48) + (b[j] - 48) + y;
        c[k] = x%10 + 48;
        y = x/10;
        k--;
        i--;
        j--;
    }

    if(i>=0)
    {
        while(i>=0)
        {
            x = (a[i] - 48) + y;
            c[k] = x%10 + 48;
            y = x/10;
            i--;
            k--;
        }
    }

    else if(j>=0)
    {
        while(j>=0)
        {
            x = (b[j] - 48) + y;
            c[k] = x%10 + 48;
            y = x/10;
            k--;
            j--;
        }
    }

    else if(y>0)
    {
        j = strlen(c);
        for(i=j;i>=0;i--)
        {
            c[i+1] = c[i];
        }
        c[0] = y + 48;
    }

    printf("\n\nSummation : %s\n", c);


    return 0;
}

Comments