Ask Question

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

+5
Answers (1)
  1. 7 March, 12:43
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers