Find the sum of the following series:
S = 5+ 55 +555+ 5555+........ upto n terms.
Answers
Answer:
Explanation:
Given series is
We know,
Sum of n terms of a GP series having first term a and common ratio r is given by
So, using these results, we get
Hence,
______________________________
#include <stdio.h>
#include <math.h>
int main()
{
int n, i, sum = 0;
printf("Enter the number of terms: ");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
sum += (int)(pow(10, i) - 1) / 9 * 5;
}
printf("The sum of the series is: %d", sum);
return 0;
}
______________________________
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of terms: ");
int n = sc.nextInt();
int sum = 0;
for (int i = 1; i <= n; i++) {
int num = Integer.parseInt("5" + String.format("%0" + (i - 1) + "d", 0));
sum += num;
}
System.out.println("Sum of the series: " + sum);
}
}
______________________________
def sum_series(n):
sum = 0
for i in range(1, n+1):
sum += int(str(5) * i)
return sum
n = int(input("Enter the number of terms: "))
print("The sum of the series upto", n, "terms is:", sum_series(n))
______________________________
______________________________