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 : Data types of LONG To define the data

    To define the data types such as LONG, INT, SHORT, CHAR write a program?

  • Q : What is Character set encoding

    Character set encoding: The set of values allocated to characters in a character set. Associated characters are frequently grouped with consecutive values, like the digits and alphabetic characters.

  • Q : Define the term Boolean Boolean : It is

    Boolean: It is one of the Java's primitive types. The Boolean type has merely two values: true and false.

  • Q : Kernel Mode Illustrate what are the

    Illustrate what are the different functions of Kernel Mode, interrupts and system calls?

  • Q : Define Fetch-execute cycle

    Fetch-execute cycle: The simple set of steps which are endlessly recurring by a computer's Central Processing Unit for each and every program instruction: `Fetch the next instruction suggested by the program counter,' `update the program counter to pa

  • Q : Define Class scope Class scope :

    Class scope: Private variables stated outside the methods in a class contain class scope. They are available from all methods within a class, in spite of the order in which they are stated. The private methods too contain class scope. Variables and me

  • Q : Explain why java is so important for

    The internet aided java to the forefront of programming. And java consequently has had a deep effect on the internet. The reason for this is highly simple: java uses the universe of objects that can travel freely in cyber space. In a network, two broad categories of

  • Q : What is an Object construction Object

    Object construction: The creation of an object, generally through the new operator. Whenever an object is formed, a suitable constructor from its class is summoned.

  • Q : Are you sure that XHTML element name

    Are you sure that XHTML element name case sensitive? Answer: XHTML element names surely are case sensitive. Every element names should be written within lower case l

  • Q : State the term WSDL State the term WSDL

    State the term WSDL?

©TutorsGlobe All rights reserved 2022-2023.