0

Another question

https://sololearn.com/coach/666/?ref=app What is wrong with this and how do I make it correct?

12th Nov 2021, 6:56 PM
Andrius Savčiukas
5 ответов
+ 2
Paul The program you are given takes a positive number N as input. Complete the program to calculate the sum of all numbers from 1 to N inclusive. Sample Input 4 Sample Output 10 1+2+3+4 int N = Convert.ToInt32(Console.ReadLine()); int sum = 0; //your code goes here for (int i = 1; i <= N; i++){ sum += i;
12th Nov 2021, 9:26 PM
BroFar
BroFar - avatar
+ 1
Can you tell us what the code is supposed to do. The code coach is for PRO only? I can't see it.
12th Nov 2021, 9:14 PM
Paul
Paul - avatar
+ 1
Paul I managed to do it but, but don’t understand how. The code is supposed to sum up every number that is from 1 to N. Ex. N=5, then the answer would be 15, because 1+2+3+4+5=15 and etc.
12th Nov 2021, 9:24 PM
Andrius Savčiukas
0
{ int N = Convert.ToInt32(Console.ReadLine()); int sum = 0; int sum1 = 0; //your code goes here for(;sum<N;sum+=1) { } Console.WriteLine(sum); } This is the closest I got. I don’t know how to add all results of each loop together
12th Nov 2021, 8:18 PM
Andrius Savčiukas
0
It should be sum <= N In the loop you should add every value of sum to sum1. And you should print sum1 after the loop is finished.
12th Nov 2021, 9:33 PM
Paul
Paul - avatar