Wednesday, 10 September 2014

C Language program to find the sum of squares of N natural numbers with Example

This C program will let you know about “find the sum of squares of N natural numbers?”. This C source code is coming under the part of C beginners guide. Feel free to use this code or if you can just contribute as a program writer.
 
SUM OF SQUARES OF N NUMBERS
Sum of squares of “n” numbers in c is used to find the square value of a number by using looping statement (for loop). It finds the power value of a given number and adds like wise. It is an easy and efficient way.

//Header files
#include<stdio.h>
#include<conio.h>
#include<math.h>
 
void main()
{
    //Program variables
    int j,num,su=0;
 
    clrscr(); //Function to clear the previous output
    printf("Enter the value:"); //Display function
    scanf("%d",&num); //Getting input function
    for(j=1;j<=num;j++) //Looping statement
    {
        su+=pow(j,2);
    }
    printf("Sum of square = %d",su);
    getch();
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.