Commit fded6ba
committed
feat: Calculate sum of first N natural numbers using for loop
🧠 Logic:
- Read user input `n` for number of terms.
- Initialize sum to 0.
- Loop from 1 to `n`, adding each number to `sum`.
- Print the final sum after the loop completes.
Signed-off-by: Somesh diwan <[email protected]>1 parent d9d9eb3 commit fded6ba
1 file changed
+24
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
1 | 17 | | |
2 | | - | |
| 18 | + | |
3 | 19 | | |
4 | 20 | | |
5 | 21 | | |
6 | | - | |
| 22 | + | |
| 23 | + | |
7 | 24 | | |
8 | 25 | | |
9 | 26 | | |
10 | 27 | | |
11 | | - | |
| 28 | + | |
12 | 29 | | |
13 | 30 | | |
14 | 31 | | |
15 | 32 | | |
16 | 33 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 34 | + | |
21 | 35 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 36 | + | |
27 | 37 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
| 38 | + | |
| 39 | + | |
0 commit comments