The for Loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The for Loop

I have another a little problem about the code. 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

22nd Mar 2021, 5:54 PM
Sebastian Górski
Sebastian Górski - avatar
6 Answers
+ 4
The value of N is to be entered by the user. https://code.sololearn.com/cPDbpuhAbjSS/?ref=app
22nd Mar 2021, 6:09 PM
Soumik
Soumik - avatar
+ 3
Sebastian Górski Don't call yourself stupid. It is quite common to overlook things and make silly mistakes. Happens to me as well 😅
22nd Mar 2021, 6:13 PM
Soumik
Soumik - avatar
+ 2
Sebastian Górski Noone is stupid. Just need sometimes to understand things. So don't worry and try to understand concepts.
22nd Mar 2021, 6:13 PM
A͢J
A͢J - avatar
+ 1
I'm so stupid... Thank you so much
22nd Mar 2021, 6:11 PM
Sebastian Górski
Sebastian Górski - avatar
0
using System; namespace SoloLearn { class Program { static void Main(string[] args) { int sum = 0; for (int N = 1; N <= 100; N++) { sum += N; } Console.WriteLine(sum); } } } What I need to do. In this example, I can only make Test case 1 How to change this line "for (int N = 1; N <= 100; N++)" "for (int N = 1; N <= ???; N++)" ?
22nd Mar 2021, 5:55 PM
Sebastian Górski
Sebastian Górski - avatar
0
@Sebastian Górski Even I got stuck at first but after seeing your response I got on track. Thanks, mate.
3rd Jun 2021, 12:46 PM
Abhik Mukherjee
Abhik Mukherjee - avatar