+ 1

In c++ when you want to use the sum value, you should put int sum = 0; first or just int sum;?

Sum in C++

6th Nov 2023, 7:11 PM
Magdalini
Magdalini - avatar
2 Respuestas
+ 1
I do something like that. int sum=0; for(int i=0;i<SomeMaxValueOfArray;i++){ sum+=Array_Used[i]; } cout<<sum<<endl;
6th Nov 2023, 8:37 PM
Werg Serium
Werg Serium - avatar
+ 1
firstly if you want to find sum of 2 or more value , it not important to name them sum you can name that var anythinge (eg.x,ab,a,s and etc) , and if you want to assign value for that sum var you have to use '=' sign (eg. int sum=10)
7th Nov 2023, 12:05 PM
Alhaaz
Alhaaz - avatar