Ask Question
6 November, 18:28

write a short C function that takes an integer n and returns the sum of all integers smaller than n.?

+2
Answers (1)
  1. 6 November, 18:55
    0
    "int sumofintegers (int n)

    {

    int cnt, sum;

    sum = 0;

    for (cnt = 0; cnt
    {

    sum = sum + cnt;

    }

    return sum;

    }

    The above function receives the 'n' as input and then initialize two variable cnt is used for looping and sum variable to add the numbers which are smaller than the given number.

    A for loop is run from 0 to n (not including n since we need to add integers less than n) and then add each value. When the counter reaches n, for loop is exited and the sum is returned to the calling portion.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “write a short C function that takes an integer n and returns the sum of all integers smaller than n.? ...” 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