Adding two integers represented by linked lists
<p><strong>The question I came across.</strong><a href="https://i.stack.imgur.com/exXkn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/exXkn.jpg" alt="Question"></a></p>

<p><strong>Here is what I have done so far</strong></p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

struct node
{
  int digit;
  struct node *next;
};

struct node *make_node(int num, struct node *head);
struct node *newNode(int digit);
struct node *sum(struct node *num1, struct node *num2);
void print(struct node *node);

int main()
{

  int a, b;
  struct node *new_nodeA1 = NULL, *new_nodeA2 = NULL;
  struct node *new_nodeB1 = NULL, *new_nodeB2 = NULL;
  struct node *res = NULL;

  printf("\nEnter no. of digits for your two numbers (separate with space)  ");
  scanf("%d %d", &amp;a, &amp;b);
  int n1[a], n2[b];

  printf("\n\nEnter first non-negative integer to add:  ");
  for (int j = 0; j &lt; a; j++)
    scanf("%1d", &amp;n1[j]);
  printf("Enter second non-negative integer to add:  ");
  for (int k = 0; k &lt; b; k++)
    scanf("%1d", &amp;n2[k]);

  /* for (int i = 0; i &lt;= a - 1; i++)
    printf("%d\n", n1[i]);

    printf("%d\n", a); */

  for (int z = 0; z &lt; a - 1; z++)
    {
      new_nodeA2 = make_node(n1[z], new_nodeA1);
      /*new_nodeA2 = newNode(n1[z]);*/
      if (new_nodeA1 == NULL)
    new_nodeA1 = new_nodeA2;
    }

  for (int y = 0; y &lt; b - 1; y++)
    {
      new_nodeB2 = make_node(n2[y], new_nodeB1);
      if (new_nodeB1 == NULL)
    new_nodeB1 = new_nodeB2;
    }

  printf("\n");
  print(new_nodeA1);
  printf("\n");
  print(new_nodeB1);
  printf("\n")
  res = sum(new_nodeA2, new_nodeB2);
  printf("Result: ");
  print(res);
  return 0;

}

struct node *make_node(int num, struct node *head)
{

  struct node *temp = malloc(sizeof(struct node));

  if (temp == NULL)
    {
      fprintf(stderr, "Call of malloc() failed\n");
      exit(1);
    }

  if (head != NULL)
    head-&gt;next = temp;

  temp-&gt;digit = num;
  temp-&gt;next = NULL;

  return temp;

}

struct node *newNode(int digit)
{
    struct node *new_node = (struct node *) malloc(sizeof(struct node));
    new_node-&gt;digit = digit;
    new_node-&gt;next = NULL;
    return new_node;
}

struct node *sum(struct node *num1, struct node *num2)
{
    struct node *res = NULL;
    struct node *temp, *prev = NULL;
    int carry = 0, sum;

    while (num1 != NULL || num2 != NULL)
    {
        sum = carry + (num1? num1-&gt;digit: 0) + (num2? num2-&gt;digit: 0);
        carry = (sum &gt;= 10)? 1 : 0;
        sum = sum % 10;


        temp = newNode(sum);


        if(res == NULL)
            res = temp;
        else
            prev-&gt;next = temp;

        prev  = temp;

        if (num1) 
      num1 = num1-&gt;next;
        if (num2) 
      num2 = num2-&gt;next;
    }

    if (carry &gt; 0)
      temp-&gt;next = newNode(carry);

    return res;
}

void print(struct node *node)
{
    while(node != NULL)
    {
        printf("%d-&gt;", node-&gt;digit);
        node = node-&gt;next;
    }
    printf("\n");
}
</code></pre>

<p><strong>My Output</strong></p>

<p><a href="https://i.stack.imgur.com/nyb4s.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nyb4s.jpg" alt="Output"></a></p>

<p>My compiler does not give me any error. I tried debugging my <code>make_node</code> function but I cant catch the problem as to why my nodes are skipping certain digits.</p>