ProAnswers.org

C program for Finding sum of the series

Finding sum of the series

	#include

	int pow(int n, int k)

	{

	    int i,p;

	    p=1;

	    for(i=1;i<=k;i++)

	        p=p*n;

	    return p;

	}

	 

	main()

	{

	    int j,n,k;

	    int sum=0;

	    printf("Enter the value of n & k

");

	    scanf("%d%d",&n,&k);

	    for(j=1;j<=n;j++)

	        sum=sum+pow(j,k);

	    printf("Sum of (1^k) + (2^k) + (3^k) +… + (n^k) is %d",sum);

	}