Find sum of series 1^1/1+2^2/2+3^3/3...+n^n/n

Problem Statement:- Program to find the sum of series 1^1/1+2^2/2+3^3/3...+n^n/n.


 Data requirement:-

   Input Data:- n

  Output Data:-Sum

  Additional Data:-i

Program in C
  
Here is the source code of the C Program to find the sum of series 1^1/1+2^2/2+3^3/3...+ n^n/n.

Code:

#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    double sum=0.0;
    printf("Enter the range of number:");
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
      sum+=pow(i,i)/i;
    }

    printf("The sum of the series = %0.2lf",sum);
}

Input/Output:
Enter the range of number:5
The sum of the series = 701.00


Program in C++
  
Here is the source code of the C++ Program to find the sum of series 1^1/1+2^2/2+3^3/3...+ n^n/n.

Code:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,i;
    double sum=0.0;
    cout<<"Enter the range of number:";
    cin>>n;

    for(i=1;i<=n;i++)
    {
      sum+=pow(i,i)/i;
    }
    cout<<"The sum of the series = "<<sum;
}

Input/Output:
Enter the range of number:11
The sum of the series = 2.69827e+010

Program in Java
  
Here is the source code of the Java Program to find the sum of series 1^1/1+2^2/2+3^3/3... +n^n/n.

Code:

import java.util.Scanner;
public class p19 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
    int n,i;
    double sum=0.0;
    System.out.println("Enter the range of number:");
    n=cs.nextInt();
    for(i=1;i<=n;i++){
   
    sum+=Math.pow(i,i)/i;
    }
    System.out.println("The sum of the series = "+sum);
    cs.close();
}
}

Input/Output:
Enter the range of number:
7
The sum of the series = 126126.0


Program in Python
  
Here is the source code of the Python Program to find the sum of series 1^1/1+2^2/2+3^3/3 ...+n^n/n.

Code:

import math
print("Enter the range of number:")
n=int(input())
sum=0.0
fact=1
for i in range(1,n+1):
    sum += pow(i, i) / i
print("The sum of the series = ",sum)

Input/Output:
Enter the range of number:
10
The sum of the series =  1045269999.0


Post a Comment

0 Comments