for loop to add the first n numbers
Vložit
- čas přidán 9. 09. 2024
- for loop to add the first n numbers
"Week: 3
Topic: For loop to add the first n numbers" IIT Madras welcomes you to the world’s first BSc Degree program in Programming and Data Science. This program was designed for students and working professionals from various educational backgrounds and different age groups to give them an opportunity to study from IIT Madras without having to write the JEE. Through our online programs, we help our learners to get access to a world-class curriculum in Data Science and Programming.
To know more about our Programs, please visit :
BSc Degree in Programming and Data Science - onlinedegree.i...
Diploma in Programming / Data Science - diploma.iitm.a...
It was really nice of you to bring up The Story of Gauss.
Sir it should be n+1 in the range part for for loop
problem statement: 2:03
solution: 3:44 7:40(modification)
If 'n' starts from "0"
8:00 sum of first n numbers:-
n=int(input())
print(((n*(n+1))/2)-n)
1:41 i liked this video and also made the like count to 45
It should be n+1 in range
8:44 Sum of n natural nos. = n(n+1)/2
But that formula won't be right for this problem. For first n number, sir starts from 0 to n-1. Whereas the formula is 1 to n.
8:44 If you want to Start from 0
Short ans:-
n=int(input())
print(((n*(n+1))/2)-n)
I feel that the sum of first n numbers should be starting from 1 not 0. 0 has no value in the sum.
थैंक्यू