Calculate the summation of 1 to some integer n

Write two programs to calculate the summation of 1 to some integer n using a function called

int summation(int n)

a) Using a non recursive solution, with a for(i=1, i<=n; i++) loop and b) using a recursive solution, based on the following conditions summation(n) = summation(n-1) + n, if n>0 summation(n) = 0, if n = 0

 

 

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.