मराठी

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

Advertisements
Advertisements

प्रश्न

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

S = `a - a/(2!) + a/(3!) - a/(4!) + ............................ "to n"`

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

उत्तर

import java.util.*;
public class Q1c
{public static void main(String args[])
{int n, cnt = 1;
double a, fact, term, sum = 0;
Scanner obj = new Scanner(System.in);
System.out.println("Enter the value of a");
a = obj.nextDouble();
System.out.printIn("Enter the value of n");
n = obj.nextInt();
for (int i = 1; i <= n; i++)
{fact = 1;
for (int j = 1; j <= i; j++)
fact = fact * j;
term = a / fact;
if (cnt % 2 == 0) // even term
sum = sum − term;
else // odd term
sum = sum + term;
cnt++;
}System.out.printIn("Sum of the series = " + (float)sum);
}}
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 1.1: Nested Loop - EXERCISES [पृष्ठ १४५]

APPEARS IN

अविचल Computer Applications [English] Class 10 ICSE
पाठ 1.1 Nested Loop
EXERCISES | Q IV. 1. (c) | पृष्ठ १४५
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×