#include <iostream.h>
int addition ( int n ) ;
void main ()
{
int n ;
cout<< "\n Input n : ";
cin >> n;
if ( n <= 0 )
cout<< "\n Number should be greater than zero !!!";
else
cout<< "\n Sum of 1 to "<<n<< " = "<< addition ( n ) ;
}
int addition ( int n )
{
if ( n == 1 )
return ( 1 ) ;
else
return ( n + addition ( n - 1 ) ) ;
}
0 comments:
Post a Comment