मराठी

Write the program to find the sum of the following series: S = a + a2 + a3 + .................... + an - Computer Applications

Advertisements
Advertisements

प्रश्न

Write the program to find the sum of the following series:

S = a + a2 + a3 + .................... + an

थोडक्यात उत्तर

उत्तर

import java.util.*;
public class Q3a
{public static void main(String args[])
{int a, n; 
double term, sum = 0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter the value of a");
a = obj.nextInt();
System.out.printin("Enter the value of n");
n = obj.nextInt();
for (int i = 1; i <= n; i++)
{
term = Math.pow(a, i);
System.out.printIn(term); // optional print
sum = sum + term;
}
Systern.out.println("Sum of the series = " +sum);
}}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1.09: Iterative Constructs in Java - EXERCISES [पृष्ठ १२४]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
पाठ 1.09 Iterative Constructs in Java
EXERCISES | Q VI. 3. (a) | पृष्ठ १२४
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×
Our website is made possible by ad-free subscriptions or displaying online advertisements to our visitors.
If you don't like ads you can support us by buying an ad-free subscription or please consider supporting us by disabling your ad blocker. Thank you.