हिंदी

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×