I want to write a program that gets input in separate lines (2 integers on each line) and calculates the sum of those 2 integers on each line This is my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *numbers;
int i, j;
numbers = malloc(100 * sizeof(int));
for (i = 1; i <= 100; i++)
{
for (j = 1; j <= 2; j++)
{
scanf("%d", &numbers[j]);
}
printf("%d\n", numbers[1]+numbers[2]);
}
return 0;
}
My problem is that this program gives sum right after writing 2 numbers and doesn't stop until 100 lines is reached. But I want it like this:
example input:
10 5
6 8
67 2
example output:
15
14
69
100 is just max lines an user can input. How do I do that?