0

how we can add two number in a loop

17th Feb 2018, 10:08 AM
Irfan Ghafoor
Irfan Ghafoor - avatar
3 Réponses
+ 8
First you need to know which loop you want to use, there are difference between them. Now about the "how", there are different ways to add numbers using loop, a simple one would be to use two variables, e.g. "n" and "sum" both initialized to zero, in your loop body you get user input into "n" then add that number to "sum", then after the loop you output "sum" to screen, this way you can actually add as many numbers as your loop was designed to repeat. Hth, cmiiw
17th Feb 2018, 10:59 AM
Ipang
+ 7
You're welcome : )
17th Feb 2018, 11:06 AM
Ipang
+ 1
thanku
17th Feb 2018, 11:04 AM
Irfan Ghafoor
Irfan Ghafoor - avatar