Ask Question
7 November, 19:23

Write a function that receives two numbers, m and n and calculates and displays the sum of the integers from m to n. For example, if the arguments are m = 3 and n = 7, the function should calculate 3 + 4 + 5 + 6 + 7

+3
Answers (1)
  1. 7 November, 20:39
    0
    The program to this question as follows:

    Program:

    //header file

    #include / /defining header file

    void inc (int m, int n) / /defining method inc

    {

    int sum, i; / /declaring variable

    sum=m; / /holding value of m variable

    for (i=++m; i<=n; i++) / /loop for calculate number between given range

    {

    sum=sum+i; / /adding value

    }

    printf ("sum of the integer is : %d", sum); //print value

    }

    int main () / /defining method

    {

    int m, n; / /defining integer variable

    printf ("Enter m value: "); / /message

    scanf ("%d",&m); / /input value by user in variable

    printf ("Enter n value: "); / /message

    scanf ("%d",&n); //input value by user in variable

    inc (m, n); / /calling method

    return 0;

    }

    Output:

    Enter m value: 3

    Enter n value: 7

    sum of the integer is : 25

    Explanation:

    In the above code, an "inc" function is declared, that accepts integer parameters that are "m and n", inside the method two integer variable "sum and i" is declared, which is used in the loop.

    The loop uses the user parameter to count value and uses the sum variable to calculate there sum. In the main method, two integer variable n and m are declared, which take value from the user end, and at the last, we call the inc method, that prints sum value.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function that receives two numbers, m and n and calculates and displays the sum of the integers from m to n. For example, if the ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers