Program to find the sum of series 1^1+2^2+3^3...+N^N

Problem statement:- Program to find the sum of series 1^1+2^2+3^3...+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+2^2+3^3...+N^N.

Code:
  
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    unsigned long sum=0;
    printf("Enter the range of number:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        sum+=pow(i,i);
    printf("The sum of the series = %d",sum);
}

Input/Output:
Enter the range of number:3
The sum of the series = 32

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

Code:
  
#include<stdio.h>
#include<math.h>
int main()
{
    int n,i;
    unsigned long sum=0;
    printf("Enter the range of number:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        sum+=pow(i,i);
    printf("The sum of the series = %d",sum);
}

Input/Output:
Enter the range of number:11
The sum of the series = 3658965799

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

Code:

import java.util.Scanner;
public class p4 {

public static void main(String[] args) {

Scanner cs=new Scanner(System.in);
    int n,i;
    long sum=0;
    System.out.println("Enter the range of number:");
    n=cs.nextInt();
    for(i=1;i<=n;i++)
        sum+=Math.pow(i,i);
    System.out.println("The sum of the series = "+sum);
    cs.close();
}
}

Input/Output:
Enter the range of number:
12
The sum of the series = 9211817190184

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

Code:


import math

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

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



Post a Comment

0 Comments