Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is in C. Write a program that computes the following summation usin

ID: 3696440 • Letter: T

Question

This program is in C.

Write a program that computes the following summation using a function. a + (a + 1) + middot middot middot + b = sigma^b_i = a 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 sigma^a - 1_i = 1 i and sigma^b_i = 1 i and use these to test your program. If your program is correct you should have sigma^a - 1_i = 1 i + sigma^b_i = 1 i = sigma^b_i = a 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 55

Explanation / Answer

Answer:

include<stdio.h>

int computesum(int a,int b);

int main() {

int res;
int a ;
int b;
printf("Enter a and b : ");
scanf("%d", &a);
scanf("%d", &b);
res= computesum(a,b);
printf(" Sum from %d to %d : %d is ",a,b,res);

return 0;
}

int computesum(int a,int b) {
int sum;
for (int i = a; i <= b; ++i) {
sum += i;
}
return sum;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote