+ 4
I really confused 😵
You need to make an app that calculates the sum of numbers from 1 to n, n is an input taken from user.
12 Antworten
+ 3
What have you tried?
+ 1
Share your code attempt ☺️
+ 1
Mahmoud
Start by writing down a clear set of steps for how the output can be gotten , you can start with writing down the output when n is 1 when n is 2 when n is 3 and so on then you can look at this sequance and see how can it be translated into code ,
You said you have tried a for loop you can start by checking a small part of the code like does this for loop run n times by making a dummy variable get printed and see how many times does that happen then you can try to write the idea you had for getting the sum
+ 1
Mahmoud it is always good practice to either click on the + button to insert your code /add it manually if you got no clue you can write a code thats wrong and you would most probably get help debugging it learning from that as well,
All in all it would make you get an answer much faster , and it would help you much more than a straight up answer to my belive
+ 1
Dareen Moughrabi Great! I'll try that. Thank you for your comment 🙏
+ 1
Dareen Moughrabi Thats like an algorithm?
+ 1
Chris Coder
Yeah he can reach a mathmatical expression and not need to you use a loop since there is a clear pattern after a couple of substitutions in the sequence reached
Or he can figure our how to write it in chuncks and produce a loop at least that was my aim
+ 1
You can do this using a for loop
0
Chris Coder For loob
0
Chris Coder that was very helpful. Thanks 🙏
0
Hallo