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 : Phenomenon of page fault Explain the

    Explain the phenomenon of page fault?

  • Q : State the term INODE State the term

    State the term INODE. Answer: It is a pointer to a block upon the disk and is a unique number. This holds metadata of files.

  • Q : What is XLink What is XLink? Answer: It

    What is XLink? Answer: It is a part of the XLL specification which is concerned along with specifying links among documents.

  • Q : What are good examples of XHTML

    What are the good examples of XHTML elements along with contents?

  • Q : Assembly program that reads in five

     I need to write assembly program that reads in five numbers from the user. The user can then be prompted for one of the following pieces of information to be computed and returned: . the mean of the five numbers; . the largest number in the set; . the smallest number in the set; . t

  • Q : Describe Locale Locale : The details

    Locale: The details which are dependent on conventions and customs approved by a specific country or culture. Within programs, this influences issues like number and date formatting, for example. Designers of classes must be sensitive to the locale-sp

  • Q : Define Software engineering Software

    Software engineering: It is the system of applying of an engineering discipline to the implementation, design and maintenance of the software systems.

  • Q : Limit the Use of Pre-processor

    Limit the Use of Pre-processor Directives: The C pre-processor is powerful, but unrestricted use of it can lead to code that is hard to understand and analyze. Limit its use to inclusion of header files and simple macro definitions. Avoid features suc

  • Q : What is Break statement Break statement

    Break statement: A statement employed to break out of a loop, switch statement or labeled block. In all situations, control continues with the statement instantly, subsequent to the containing block.

  • Q : Explain Wrapper classes Wrapper

    Wrapper classes: The Java's primitive types are not of object types. The wrapper classes are stated in the java.lang package. They comprises of a class for each and every primitive type: Boolean, Byte, Double, Float, Integer, Long & Short and Char

©TutorsGlobe All rights reserved 2022-2023.