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.
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.
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.
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.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 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(); }