Write a program that computes the following summation using a function. a + (a +
ID: 3555525 • Letter: W
Question
Write a program that computes the following summation using a function. a + (a + 1) + . . . + b = i Implement the following function in your program int computesum (int a, int b) This function computesum computes the sum of all the integers from a to b. You can compute the sum i and i and use these to test your program. If your program is correct you should have i + i = i Sample execution of the program is given below Enter a and b 5 10 Sum from 5 to 10 is 45 Sum from 1 to 4 is 10 Sum from 1 to 10 is 55Explanation / Answer
#include<stdio.h>
int computesum(int a,int b)
{
int sum=0;
while(a<=b)
{
sum=sum+a;
a++;
}
return(sum);
}
int main()
{
int arr[100000],a,b,k ;
printf("Enter the a and b ");
scanf("%d %d",&a,&b);
k= computesum(a,b);
printf(" Sum from %d to %d is %d",a,b,k);
return(0);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.