Question

w Problem Statement: In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many
Sample Output: X C:\Users\Imran Desktop Lab 111\Debug Lab111.exe Enter a positive integer to compute a mathematical series: 5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The above problem can be solved as follows:

  • Define the methods as specified in question
  • The comments is given in code to help in understanding the working of code.

C++ CODE-

/*Function to Compute the sum of Series and other inforamtion*/
//include the required header files
#include <iostream>
#include <math.h>
using namespace std;
//define the method Computation() that takes an integer 'n' as input parameter
//returns the values of n'th term in series
double Computation(int n){
double n_term = pow(n,3)/2.0;
return n_term;
}
//define the function isEven() that takes an integer as input parameter
//and returns whether the number is Even or not Even
bool isEven(int t){
if(t%2 == 0){
return true;
}
else {
return false;
}
}
//define the main method
int main()
{
int k;
cout<<"Enter a positive integer to compute a mathematical series : "; //prompt the user for 'k'
cin>>k; //store the values 'k'
cout<<"**************************************************************************\n";
//declare a double array to stores the series
double series[k+1]; //size is k+1, because we will use 1-based indexing here
int countEven = 0, countOdd = 0; //variables to store the count of even and odd numbers in series
double sum = 0.0; //to store the sum of series
//run a loop for terms 1 to k
for(int i=1;i<=k;i++){
//if first term, then there is no previous term to add
if(i==1){
series[i] = Computation(i); //call Computation() and store the result
}
//otherwise, the previous term will be added
else{
series[i] = series[i-1] + Computation(i); //call Computation() and add the previous term too
}
int t = ceil(series[i]); //store the ceil value of current term in series
bool val = isEven(t); //call isEven() and store the boolean value
//if value is true, means the series term is even
if(val == true){
countEven++; //increase even count
}
//otherwise, term is odd
else{
countOdd++; //increase count of odd
}
sum += series[i]; //add term to the sum
}
//display the output as shown in figure
cout<<"\nThe mathematical series of the first k terms starting from 1 to k : ";
for(int i=1;i<=k;i++){
cout<<series[i]<<" ";
}
cout<<"\nThe total number of odd integers : "<<countOdd;
cout<<"\nThe total number of even integers : "<<countEven;
cout<<"\nThe sum of series : "<<sum<<endl;
cout<<"\n**************************************************************************\n";
return 0;
}

IMAGE OF CODE-

1 /*Function to Compute the sum of Series and other inforamtion 2 //include the required header files 3 #include <iostream> 4

//otherwise, the previous term will be added else{ series[i] = series[i-1] + Computation(i); //call Computation () and add th

OUTPUT-

Enter a positive integer to compute a mathematical series : 5 ttttttttt The mathematical series of the first k terms starting

If this answer helps, please give an up vote and feel free to comment for any query.

Add a comment
Know the answer?
Add Answer to:
w Problem Statement: In mathematics, a series is, roughly speaking, a description of the operation of...
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
  • In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.......

    In mathematics, the Fibonacci numbers are the series of number that exhibit the following pattern: 0,1,1,2,3,5,8,13,21,34,55,89,144,.... In mathematical notation the sequence Fn of Fibonacci number is defined by the following recurrence relation: Fn=Fn-1+Fn-2 With the initial values of F0=0 and F1=1. Thus, the next number in the series is the sum of the previous two numbers. Write a program that asks the user for a positive integer N and generate the Nth Fibonacci number. Your main function should handle user...

  • Problem Description: Create a mathematics library with the following functionality.  calculate the absolute value of...

    Problem Description: Create a mathematics library with the following functionality.  calculate the absolute value of an integer number  calculate the power given an integer base and a positive integer exponent  calculate the square of an integer number  determine if an integer is an even  determine if an integer is prime Write a Java program to do the following: 1. Calculate the absolute value, square, cube (i.e., 3rd power) of the integers 2 through 7. 2....

  • CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri...

    CODE NEEDS TO BE IN PYTHON. OLA 5: Collatz Sequence Function 12 17 34 Due: Fri Oct 19, 2018 by 11:59 PM-may be tumed in until Oct 26 by 1159 PM with reduced points (per Open Lab- Project guidance found in the course syllabus) Assignment id: ola5 Assignment type: Project Required Files: ola5.py, myout.log Lab description: In this you will explore the Collatz mathematical sequence. This sequence eventually converges to the value 1, regardless of the initial input Requirements: 1....

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • 1. Write a program that takes a number as input and check whether the number is...

    1. Write a program that takes a number as input and check whether the number is positive, negative or zero. 2. Write a C++ program that prompts the user to enter a number and checks whether the entered number is even or odd. 3.  Using switch-case statement write a C++ program that prompts the user to enter 1, 2 or 3 and display "Red" if selection is 1, "Yellow" if selection is 2, or "Green" if selection is 3. 4. Write...

  • Assignment: Using the Fork System Call The Collatz conjecture concerns what happens when we take any...

    Assignment: Using the Fork System Call The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorthm: n={n / 2 , if n is even 3 * n + 1 , if n is odd The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is:  35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2,...

  • Within the 1900 folder on your desktop, create a new folder namned Lab4HwLastnameFirstnane (5 pts) Problem...

    Within the 1900 folder on your desktop, create a new folder namned Lab4HwLastnameFirstnane (5 pts) Problem 1 Consider the sequence of integers defined as follows: • The first term is any positive integer. . For each term n in the sequence, the next tcrin is computed like this: If n is even the next term is n/2. If n is odd, the next term is 3n +1. • Stop once the sequence reaches 1. Here are a few examples of...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

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