I'm currently working on code that reads in a sequence of integers in the form of m1, n1, m2, n2, until I input a zero, and it prints the sum of m * n. Here is what I have so far:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
int m, n, i, sum = 0;
bool plus = true;
scanf("%d", &m);
scanf("%d", &n);
for(i = m; i <= n; i++)
{
sum = sum + (m * n);
if(!plus)
{
putchar('+');
}
printf("%d*%d", m, n);
plus = false;
}
printf("=%d\n", sum);
return 0;
}
If I type in 1, 1, 0, it prints out 1 * 1 = 1, but if I were to type in, 1, 2, 3, 4, 0, it prints out 1*2+1*2=4. I'm just confused on how I get it to calculate 1*2 and 3*4.