Ask Question
11 August, 00:38

Write a recursive function sumAll that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will turn the sum of 1, 2, 3, 4, ... 50.

+4
Answers (1)
  1. 11 August, 02:44
    0
    int sumAll (int n) / /function definition.

    {

    if (n==1) / /if condition.

    return 1;

    else//else condition.

    {

    return n+sumAll (n-1); //return the value and call the function in recursive manner.

    }

    }

    Explanation:

    The above-defined function is a recursive type function that is written in the c language, which holds the if and else condition. When the user passes the largest value from 1, then the else condition will be executed which adds the largest value and pass the value after the decrement of the value as an argument. When the value will become 1, then the function if-block will be executed which returns the value and ends the calling function recursively.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a recursive function sumAll that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers