0% found this document useful (0 votes)
28 views1 page

Sum Squar

This C program uses a recursive function to calculate the sum of squares of the first n natural numbers. The function sum takes the limit n as a parameter, uses recursion to calculate the sum of squares from 1 to n, and returns the result. The main function prompts the user to input n, calls the sum function to calculate the sum, and prints out the final result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views1 page

Sum Squar

This C program uses a recursive function to calculate the sum of squares of the first n natural numbers. The function sum takes the limit n as a parameter, uses recursion to calculate the sum of squares from 1 to n, and returns the result. The main function prompts the user to input n, calls the sum function to calculate the sum, and prints out the final result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

INPUT PROGRAM:

/*PROGRAM TO FIND THE SUM OF SQUARES OF N NATURAL NUMBERS*/


#include<stdio.h>
#include<conio.h>
int sum(int n)
{
if (n==0)
return 0;
else
return (n*n)+sum(n-1);
}
void main()
{
int x,n;
clrscr();
printf("Enter the limit ");
scanf("%d",&n);
x=sum(n);
printf("Sum of squares of n natural numbers is %d",x);
getch();
}

OUTPUT:

You might also like