0

Take a number N as input and output the sum of all numbers from 1 to N (including N). Sample Input 100 Sample Output 505

FIND THE ANSWER PLEASE

14th Jul 2022, 4:53 PM
Rajesh Dilakshan
Rajesh Dilakshan - avatar
10 Antworten
+ 7
Rajesh Dilakshan , can you show us your attempt? what programming language you are talking about btw: using 100 as input should give 5050, not 505
14th Jul 2022, 5:05 PM
Lothar
Lothar - avatar
+ 5
1. take input N from the user 2. Intialize variable to store the sum to 0 3. loop from 1 to less or equal than 100 4. store sum=sum+i 5. print sum
14th Jul 2022, 5:58 PM
Aly Alsayed
Aly Alsayed - avatar
+ 5
Rajesh Dilakshan Programming is not a quiz where you may find answer it is a skills which comes from learning and practice so try to do self.
14th Jul 2022, 6:05 PM
A͢J
A͢J - avatar
+ 3
TESSY Vidjinnangni Peace Hosnie That doesnt make sense… i is always 0 so your program never stops. You should do i += 1 in every iteration
15th Jul 2022, 9:43 PM
Janne
Janne - avatar
+ 1
Thank you for your help.. i find the answer later. I understood my fault 🙂🙂🙂🙂🙂
15th Jul 2022, 3:39 PM
Rajesh Dilakshan
Rajesh Dilakshan - avatar
+ 1
Yes , thanks for this remark🤝
15th Jul 2022, 9:50 PM
TESSY Vidjinnangni Peace Hosnie
0
Tip: Use a for loop in range of 1, input
14th Jul 2022, 6:16 PM
Janne
Janne - avatar
0
print(sum)
15th Jul 2022, 9:28 PM
TESSY Vidjinnangni Peace Hosnie
- 1
In python : N=int(input()) i=0 sum=0 while i<=N sum=sum+i
15th Jul 2022, 9:28 PM
TESSY Vidjinnangni Peace Hosnie
- 2
1) Read N value from user 2) calculate the variable sum = N*(N+1)/2 2) print sum
16th Jul 2022, 12:05 PM
Pardha Saradhi