--%>

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 : Define Keyword Keyword : They are

    Keyword: They are reserve word containing special meaning of the language and cannot be employed as identifier.

  • Q : Explain Synchronized statement

    Synchronized statement: It is a statement in which an object-lock should be obtained for the target object prior to the body of the statement and can be entered. Employed to enclose a critical section in order to save a race hazard.

  • Q : Define Java virtual machine or JVM

    Define Java virtual machine (JVM): A Java Virtual Machine (JVM) is an abstract computing machine, or virtual machine (set of computer software programs and data structures) which is a platform-independent execution environment that converts Java bytec

  • Q : Explain Branch instruction Branch

    Branch instruction: It stores a new instruction address into the program counter. The consequence of this is the next instruction to be fetched will not generally be the one instantly following the branch instruction. Therefore the normal chronologica

  • Q : Explain Abstraction Abstraction : It is

    Abstraction: It is a simplified symbolization of something which is potentially quite complex. It is frequently not essential to know the precise details of how something works, is symbolized or is implemented, since we can still make use of it in its

  • Q : Program to Calculate Estimate

    Collaboration Policy Collaboration between students on programming assignments is NOT allowed under any circumstances - you may not even discuss your work with other

  • Q : Define the term Multiprogramming system

    Define the term Multiprogramming system: It is an operating system which is able to run multiple programs parallel.

  • Q : Define the term Garbage collector

    Garbage collector: It is a daemon thread which recycles objects to which there are no extant references in a program.

  • Q : Use of System Dynamic and System Runtime

    What is the use of System.Dynamic and System.Runtime.CompilerServices namespaces?

  • Q : Define the term Class constant Define

    Define the term Class constant: A variable which is defined as both final and static.