Advertisements
Advertisements
प्रश्न
Write the program to find the sum of the following series:
S = (a + 1) + (a + 2) + (a + 3) + ............... + (a + n)
संक्षेप में उत्तर
उत्तर
import java.util.*;
public class Q3b
{public static void main(String args[])
{int a, n, cnt = 1, term, sum = 0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter the value of a");
a = obj.nextInt();
System.out.println("Enter the value of n");
n = obj.nextInt();
for (int i = 1; i <= n; i++)
{term = a + i;
sum = sum + term;
}
System.out.println("Sum of the series = " + sum);
}}
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 1.09: Iterative Constructs in Java - EXERCISES [पृष्ठ १२४]