C program to Calculate (1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n) series

In c language you can print any number series. Here i will show you how to print number series in c language with explanation. In case of print number series you need to focus on common difference between two numbers..

C program to Calculate (1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n) series




#include<stdio.h>
long power(int a, int b)
{
    long i, p=1;
    for(i=1;i<=b;i++)
    {
        p=p*a;
    }
    return p;
}

int main()
{
    long i,n,sum=0;
    n=5;
    for(i=1;i<=n;i++)
    {
        sum=sum+power(i,i);
    }
    printf("Sum: %d",sum);
    return 0;
}



Output:


sum: 3413




#include <stdio.h>
#include <stdlib.h>

long power(int a, int b)
{
    long i, p=1;
    for(i=1;i<=b;i++)
    {
        p=p*a;
    }
    return p;
}

int main()
{
    long i,n,sum=0;
    printf("\n Enter n value (1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n):");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        sum=sum+power(i,i);
    }
    printf("Sum: %d",sum);
    return 0;
}




Output:



Enter n value (1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n):10
Sum: 1815136725
Process returned 0 (0x0)   execution time : 2.114 s





Instagram