25. Write a program to evaluate the series 1^2+2^2+3^2+……+n^2
#include<stdio.h>
#include<conio.h>
#include<math.h> /* Here we are using math.h header file because we are using pow function under this header file. */
void main()
{
int i,n,sum=0;
printf("Enter your Numbers: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+pow(i,2);
}
printf("Sum=%d",sum);
getch();
}
#OUTPUT:
#include<conio.h>
#include<math.h> /* Here we are using math.h header file because we are using pow function under this header file. */
void main()
{
int i,n,sum=0;
printf("Enter your Numbers: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+pow(i,2);
}
printf("Sum=%d",sum);
getch();
}
#OUTPUT:
Comments
Post a Comment