my loop is looping one less time

I wrote a code to find the lcm of multiple numbers, but the loop is looping one less time. The first line of the input contains a positive integer N, and each of the next N lines contains 2 space-separated integers. The code will then add each of the two intengers and calculate the lcm of the sums. I think I have made a stupid mistake in the last loop, but I can't find it. I am a beginner, so please point out my stupid mistake in the code. Thank you!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <cstdio>
lcm (int x, int y){
	if (x > y){
	        for (int i = 1; i <= y; i++){
			if ((x * i) % y == 0){
				int lcm = x * i;
				return lcm;
				break;
			}
		}
	}else if (x < y){
		for (int i = 1; i <= x; i++){
			if ((y * i) % x == 0){
				int lcm = y * i;
				return lcm;
				break;
			}
		}
	}
}
int main (){
	int number = 0;
	scanf("%d",&number);
	int a[number] = { };//The first intengers or the sum of the 2 intengers
	int b[number] = { };//The second intengers
	int c = 1;
	while (c < number){
		scanf("%d %d\n",&a[c],&b[c]);
		a[c] += b[c];
		c++;
	}
	int n = 1;
	int d = 0;
	while (d < number){
		n = lcm(n, a[d]);
		if (d == number - 1){
			printf("%d\n",n);	
		}
		d++;
	}	
}


Some inputs and outputs:
test1:
3 input
1 3 input
2 4 input
5 8 input
12 output

test2:
4 input
1 2 input
2 3 input
3 4 input
4 5 input
105 output
1
2
	int c = 1;
	while (c < number){
suppose that you just have one testcase. So number is 1.
1<1 is false.
thank you!
but now the second last loop is running one more time and force me to input number + 1 times.
let me see if I understand.
The second loop was working fine, but you decided to edit it. Now it fails, but you don't think that it's necessary to show your changes.

good luck
Last edited on
Topic archived. No new replies allowed.