--%>

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

  • Q : Platform security of S60 third Edition

    How do I know that platform security abilities my S60 3rd Edition application needs?

  • Q : Describe Last in-first out Last in,

    Last in, first out: It is the LIFO semantics of a stack data structure. Items are eliminated in the opposite order to which it arrived in the stack; therefore newer items are always eliminated before older ones.

  • Q : Explain Relative filename Relative

    Relative filename: It is a filename whose full path is associative to some point within a file system tree-frequently the present working folder (that is, directory). For example:   

  • Q : Throughout system testing the

    Someone complains that throughout system testing the application frequently crashes. What probable process problem does which indicate?

  • Q : Generating uniform random numbers using

    In .NET, write a simple web service in C# to generate uniform random numbers. Use the class System.Random to generate the random numbers. What part of the code is specifically associated with web services? How could you deploy the web service?

  • Q : Define Sign bit Sign bit : In

    Sign bit: In 2s-complement notation, the most important bit in an integer value is employed to determine the sign of the value. A 1-bit point out a negative number and a 0 bit point out a positive number.

  • Q : Explain Cast Cast : Where Java does not

    Cast: Where Java does not allow the utilization of a source value of one type, it is essential to use a cast to force the compiler to admit the use for the target type. The care must be taken with casting values of primitive types, as this frequently

  • Q : Define the term Swizzling Define the

    Define the term Swizzling: It is the process of recursively writing the contents of an object through object serialization.

  • Q : ASP.NET Session handling How to set

    How to set Session time out in ASP.NET. I tries changing in config file but still facing issue. Please help..

  • Q : Explain Interpreter Interpreter : A

    Interpreter: A program that executes a translated version of the source program by implementing a virtual machine. The interpreters usually simulate the actions of an idealized Central Processing Unit. An interpreter for Java should implement the Java