Skip to content

Commit 93cecb2

Browse files
committed
feat: Generate arithmetic progression series up to n terms
🧠 Logic: - Read first term `a`, common difference `d`, and number of terms `n`. - Initialize `term` with `a`. - Use a loop running `n` times: - Print current `term` - Update `term = term + d` to get the next AP value. Signed-off-by: Somesh diwan <[email protected]>
1 parent f4647c0 commit 93cecb2

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

Section8LoopAB/src/ArithimaticSeries.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@ public static void main(String[] args) {
99
System.out.println("Enter a, d and n");
1010

1111
int a = sc.nextInt();
12-
1312
int d= sc.nextInt();
14-
1513
int n = sc.nextInt();
1614

1715
int term = a;
1816

19-
for(int i=0; i<n; i++)
20-
{
17+
for(int i=0; i<n; i++) {
2118
System.out.print(term+",");
22-
2319
term=term+d;
2420
}
2521
}

0 commit comments

Comments
 (0)