0
680views
WAP to print the sum of the following series

$1 + 2^2 + 3^3 + ... + n^n$

Subject : Structured Programming Approach

Title : Control Structures

Difficulty : Medium

1 Answer
0
0views

Program:

#include<stdio.h>

#include<conio.h>

void main()

{

    int n,sum=0;

    clrscr();

    printf("Enter a number ");

    scanf("%d",&n);

    while(n!=0)

    {

        sum=sum+(n*n);

        n--;

    }

    printf("The sum of the series is %d",sum);

    getch ();

}

Output:

Enter a number 3

The sum of the series is 14
Please log in to add an answer.