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
10 ответов
+ 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
+ 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
+ 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.
+ 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
+ 1
Thank you for your help.. i find the answer later. I understood my fault 🙂🙂🙂🙂🙂
+ 1
Yes , thanks for this remark🤝
0
Tip: Use a for loop in range of 1, input
0
print(sum)
- 1
In python :
N=int(input())
i=0
sum=0
while i<=N
sum=sum+i
- 2
1) Read N value from user
2) calculate the variable sum = N*(N+1)/2
2) print sum