Commit 82ad8ce
committed
feat: Calculate sum of all elements in an array using enhanced for loop
🧠 Logic:
- Declare and initialize an integer array `A` with 10 elements.
- Initialize a variable `sum` to 0.
- Use an enhanced for loop to iterate over each element in the array and add it to `sum`.
- Print the total sum after the loop completes.
- (Optional) Includes a commented version using traditional for loop for alternative approach.
Signed-off-by: Somesh diwan <[email protected]>1 parent 5faa8d1 commit 82ad8ce
1 file changed
+4
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 3 | + | |
| 4 | + | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
11 | | - | |
12 | | - | |
| 9 | + | |
13 | 10 | | |
14 | 11 | | |
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
18 | | - | |
19 | | - | |
| 15 | + | |
20 | 16 | | |
21 | 17 | | |
22 | 18 | | |
| |||
0 commit comments