1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Mnenie [13.5K]
3 years ago
11

For this lab, youhave to write a programnamedseriesFunction.cthat prompts user to enter two values, x and n. Then it would use a

function to compute the sum of the series. It will take two arguments, x and n. It will return the sum of the series.

Computers and Technology
1 answer:
Komok [63]3 years ago
4 0

The question is incomplete! Here is the complete question and it’s answer!

Question:

For this lab, you have to write a programnamedseriesFunction.cthat prompts user to enter two values, x and n. Then it would use a function to compute the sum of the series. It will take two arguments, x and n. It will return the sum of the series.

S(x) = x + (x+1) + (x+2) + (x+3) + (x+4) +........................+(x + n - 1) + (x + n)

As an example, for input values x = 100 and n = 0, it should output 100. For x = 100 and n = 1, it should output 100 + 101 = 201.

Step by Step Explanation:

We are required to find the sum of the following series.

S(x) = x + (x+1) + (x+2) + (x+3) + (x+4) +........................+(x + n - 1) + (x + n)

We have created a function seriesFunction which takes two inputs x and n and calculates the sum of the series (x+n). A for loop is used to run n times and a sum variable is used to keep adding n number of times.

Then we have driver code in the main function where we ask the user to enter x and n values and then called the seriesFunction to calculate the sum of series

Code:

#include <iostream>

using namespace std;

 int seriesFunction(int x, int n)

 {

     int sum;

     for(int i = 0; i <= n; i++)

     sum = sum + (x+i);

     cout<<"sum of series: "<<sum<<endl;

 }

int main()

{

   int x,n;

   cout << "Enter x"<<endl;

   cin >> x;

   cout << "Enter n"<<endl;

   cin >> n;

   seriesFunction(x,n);

   return 0;

}

Output:

Test 1:

Enter x

100

Enter n

1

sum of series: 201

Test 2:

Enter x

100

Enter n

4

sum of series: 510

You might be interested in
Write a program that reads a file containing text. Read each line and send it to the output file, preceded by line numbers. If t
Shtirlitz [24]

Answer:

I am writing a JAVA program:

import java.io.FileReader;  // class used for reading data from a file

import java.io.IOException;  //class used for handling exceptions

import java.io.PrintWriter;  // class used to printing or writing formatted data. It is used when the data to be written contains text and numbers

import java.util.Scanner;   // class used to take input from the user

public class Main  {  //start of the class

public static void main(String[] args)  {//start of main() function body

Scanner input = new Scanner(System.in);  //creates Scanner class object

System.out.print("Enter the input file name: ");  // prompts user to enter the input file name

String input_file = input.next();  //to  read and return the token i.e. input file name and store this into input_file String type variable

System.out.print("Enter the output file name: "); // prompts user to enter the output file name

String output_file = input.next();   /to  read and return the token i.e. output file name and store this into output_file String type variable

try   {/* try  defines a chunk of code to be tested for errors during the execute of this chunk. its a code block for reading from input file and writing to output file. This handles the exception if program cannot create or write to the file indicated. */

   FileReader inFile = new FileReader(input_file);  //creates object inFile of FileReader class to read the input_file contents

   Scanner scan = new Scanner(inFile);  //read and scans the input file

   PrintWriter outFile = new PrintWriter(output_file);  //creates object outFile of PrintWriter class to write to the output file. It is used to write output data in a readable text form.

   int count = 1;    //counts the line number      

   while (scan.hasNextLine())  {  //loop keeps checking for the next line in input file

    String lines = scan.nextLine();  // reads the entire line of the input file and stores that line contents in String lines

    outFile.println("/* " + count + " */ " + lines);  //each line represented with line number enclosed in /* */

    count++;  }   //increments the line number at each iteration    

    outFile.close();        }  //closes the output file after writing the contents from input file with each line of the input file enclosed in  /* */

catch (IOException e)  {  // catching the IOException and prints the following message if program cannot create input_file or write to the output_file

   System.out.println("Error processing file: " + e);    }     }   }

Explanation:

The program is well explained in the comments mentioned with each statement of the above program. The user is prompted to enter input and output file names. Then the program uses a while loop that scans through lines of the input file and count variable counts each line of input file. Then at each iteration the count variable counts a line of input file and line number of each line of the input file is enclosed in /* */ delimiters. The contents of input file, in which the line numbers of text lines of the input file are enclosed in /* */ delimiters, is written to the output file.

The screenshot of the program is attached along with the output file produces as a result of this program execution.

7 0
3 years ago
3) An algorithm has a run time of O(nk ) for some integer k. On an input of size 500, the algorithm takes 16 seconds to run. On
lukranit [14]

Answer:

The value of k is 4

Explanation:

Solution

Given that:

k = integer

Input size = 500

The algorithm takes a run of = 16 seconds

Input size = 750

The algorithm takes a run of = 81 seconds

Now,

We have to determine the value of k

The equation is shown below:

(500)^k /16 = (750) ^k /81

Thus

(750/500)^ k = 81/16

= (3/2)^k

=(3/2)^ 4

k is = 4

6 0
3 years ago
Do opportunity costs only occur when making spending decisions
Naily [24]

Answer:

yes there is opportunity in every thing such as do i buy this car what am i going to miss out on if i buy this what does this offer

Explanation:

6 0
3 years ago
How many total channels are available in the United States for wireless LAN use in the unlicensed 2.4ghz ism band ?
Usimov [2.4K]
Answer: 14 channels are available in the unlicensed 2.4 GHz ISM band.
3 0
3 years ago
Why should running your unit test suites not take a long time?A. Unit tests aren't that important, so less time should be spent
masya89 [10]

Answer:

D. Tests that run too long risk slowing down the feedback cycle for developers

Explanation:

The reason you should run your unit test suites not to take a long time is that "Tests that run too long risk slowing down the feedback cycle for developers."

Otherwise, the developers would find it difficult to detect problems instantly, causing delay to fix the problems which will eventually delay the developers or project's team to advance to the next stage of the project.

3 0
3 years ago
Other questions:
  • Can someone can help me am dont know how much RAM do i need. I use my pc for work and to watch yt vid. Thanks​
    10·1 answer
  • Data bars describe a graphic element that
    9·2 answers
  • Samuel is working on decimal and binary conversion for his college project.He is using the binary number 111011 and wants to exp
    8·1 answer
  • Which of the following are reasons why it is important to properly recycle electronic equipment? Select all that apply.
    14·2 answers
  • Animations and transitions are added from the _____.
    11·2 answers
  • What are the two types of commennts of java​
    12·1 answer
  • Free points <br><br><br><br><br> also if u wanna check out my spotlfy u can (xkuromist)
    6·2 answers
  • In the earliest stages of human history, what was the only medium?
    10·1 answer
  • Business Rules constraints falls into two categories:
    7·1 answer
  • Frequently used _____________ can be saved as _____________ for use in analysis, dashboards, reports, tickets, and alerts.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!