Skip to main content
Search
Search This Blog
CODERS WORLD
Home
PROGRAMMING NOTES
CPP NOTES
HTML CODES
SQL NOTES
PHP CODES
Java Sciript
About
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
Labels
cpp
October 02, 2018
Program to print sum of n numbers using recursive function
#include<iostream>
using namespace std;
int sum(int n)
{
if (n==1)
return 1;
else
return n+sum(n-1);
}
int main()
{
int n,z;
cout<<"enter the limit of value of n:";
cin>>n;
z=sum(n);
cout<<"sum : "<<z;
}
Comments
Comments
Post a Comment