+ 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.

27th Jul 2024, 7:44 PM
Mahmoud
Mahmoud - avatar
12 Antworten
+ 3
What have you tried?
27th Jul 2024, 7:46 PM
Chris Coder
Chris Coder - avatar
+ 1
Share your code attempt ☺️
27th Jul 2024, 7:55 PM
Chris Coder
Chris Coder - avatar
+ 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
28th Jul 2024, 3:24 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 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
28th Jul 2024, 3:26 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
Dareen Moughrabi Great! I'll try that. Thank you for your comment 🙏
28th Jul 2024, 12:50 PM
Mahmoud
Mahmoud - avatar
+ 1
Dareen Moughrabi Thats like an algorithm?
28th Jul 2024, 6:40 PM
Chris Coder
Chris Coder - avatar
+ 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
28th Jul 2024, 7:15 PM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
You can do this using a for loop
29th Jul 2024, 8:33 AM
Divyanshi Shaw
0
Chris Coder For loob
27th Jul 2024, 7:47 PM
Mahmoud
Mahmoud - avatar
0
Chris Coder that was very helpful. Thanks 🙏
28th Jul 2024, 12:48 PM
Mahmoud
Mahmoud - avatar
0
Hallo
29th Jul 2024, 2:56 PM
Prakash Chand
Prakash Chand - avatar