Question

Write a function to calculate the sum of the reciprocals of a series of odd numbers....

  1. Write a function to calculate the sum of the reciprocals of a series of odd numbers. The function will have one input and no output, with the input being the ending value for the series of odd values.

  1. Write the function definition statement
  2. Initialize a variable to zero. This variable will contain the sum of all the values.
  3. Create a for loop that loops over all odd numbers from 1 to the specified ending value.
  4. Inside the loop, add the reciprocal of the current loop index to the running sum (variable defined in step b.)
  5. End the loop.
  6. Print the result to the screen using fprintf and specifying 6 decimal places.
  7. End the function.

If you run it with an input of 51 you should get the result:

total = 2.610834

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>

void priodd(int);
int main()
{
int n;
printf("Enter odd number");
scanf("%d",&n);
priodd(n);

return 0;
}
void priodd(int n)
{
int i;
float sum=0;
for(i=1;i<=n;i=i+2)
{
sum=sum+(1.0/i);
}
fprintf(stdout,"%0.6f",sum);
}

Add a comment
Know the answer?
Add Answer to:
Write a function to calculate the sum of the reciprocals of a series of odd numbers....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

  • Write a C program to sum up all the odd numbers between a lower limit number...

    Write a C program to sum up all the odd numbers between a lower limit number and an upper limit number provided by a user. The requirements are: First, request the user to provide a lower limit integer number and an upper limit integer number that is larger than the lower limit number, and save them in variables lowerLimit and upperLimit, respectively. If the user has entered an upper limit number (upper Limit) that is NOT larger than the lower...

  • Write a for loop that assigns summed Value with the sum of all odd values from...

    Write a for loop that assigns summed Value with the sum of all odd values from 1 to user Num. Assume userNum is always greater than or equal to 1. Ex: If userNum is 5, then summed Value is 9 (i.e. 1+3+5 =9). Function Save C Reset MATLAB Documentation 1 function summedValue - Oddssum(userNum) summedValue = 0; % Write a for loop that assigns summedValue with the % sum of all odd values from 1 to user Num 7 end...

  • in C++ Extract and Add a Series of Numbers: Write a program that will extract a...

    in C++ Extract and Add a Series of Numbers: Write a program that will extract a series of numbers (type double) from an input sentence and then add them. EXAMPLE: Suppose the sentence entered is “Give me the sum of 25.25 and 13.50. ”The program should print to the screen: The sum = 38.75 NOTE: The numbers can be of any value. Don’t hard code to the values shown in the example. In this problem take advantage of the input...

  • c++ language Consider the series of numbers beginning at user-specified start and running up to but...

    c++ language Consider the series of numbers beginning at user-specified start and running up to but not including user-specified end, so for example start=1 and end=5 gives the series 1, 2, 3, 4. Return a new string[] array containing the string form of these numbers (e.g. "one", "two", "fifty-three" etc., except for multiples of 3, use "Fizz" instead of the number, for multiples of 5 use "Buzz", and for multiples of both 3 and 5 use "FizzBuzz". Test with numbers...

  • Write a regular function (i.e. in a function .m file) to calculate the series expansion of...

    Write a regular function (i.e. in a function .m file) to calculate the series expansion of cosine(x). The number of terms calculated in the series should be specified in the input list of the function. Write a separate function that determines when the series expansion begins to deviate by at least 10% from the true value of cosine(x) based on the number of terms calculated in the series expansion, n. For n = 1, 2, … 10, determine the values...

  • Step 2. Write a C function to passed two numbers to the function and calculate the...

    Step 2. Write a C function to passed two numbers to the function and calculate the sum of all the numbers between them (both inclusive). [50 marks] a. Make a version with for loop b. Make a version with while loop c. Make a version with do.. while loop d. Make a version with goto loop Tip : Try to use the same number of variables and almost the same logic in all the four loops To do: Using the...

  • •The multiplication operator works by summing some value, x, by another value, y. Write a function...

    •The multiplication operator works by summing some value, x, by another value, y. Write a function definition called multiply that takes two integer parameters to perform the operation described. Return the answer to the calling function. •Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function. •Write a function called summary that takes as...

  • Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values...

    Write VBA functions to calculate sin (x) using the Maclaurin arcsine series, and compare the values for sin-1(x) from your program to those given by the Excel spreadsheet function ASIN(x). The Maclaurin arcsine expansion is given by x 3x 6 40 (2n)! sin1(x)-2((2n+1) Note: This function by definition is only defined for-1 SxS1. When you write the code for calculating it, you will need to include code that assigns a value to it that reflects it is undefined for values...

  • Write a program with loops that compute a.The sum of all even numbers between 2 and...

    Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT