Question

In: Computer Science

1. Write a program in C++ that takes as inputs a positiveinteger n and a...

1. Write a program in C++ that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the powern and stores the result as a protected variable. That is, the sum is: 1 + ? + ? ^2 + ? ^3 + ? ^4 + ⋯ + ? ^?

2.  Write a program in C++ that takes as input a positive integer n and computes the following productsum mix: 1 * (1+2) * (1+2+3) * (1+2+3+4)*…*(1+2+3+…+n) and stores the result as a protected variable.

Solutions

Expert Solution

#include
#include

using namespace std;

int main() {
   float a, n, i, term, sum;
   cout << "Enter a: ";
   cin >> a;
   cout << "Enter n: ";
   cin >> n;

   if (n > 0) {
      term = a;
      sum = 1;
      for (i = 1; i < n; i++) {
         sum += term;
         term = term + a;
      }
      cout << "Sum of geometric series: " << sum << endl;
   }

   system("pause");
   return 0;
}

=================================
#include
#include

using namespace std;

int main() {
   float a, n, i, term, p;
   cout << "Enter a: ";
   cin >> a;
   cout << "Enter n: ";
   cin >> n;

   if (n > 0) {
      term = 1;
      p = 1;
      for (i = 2; i < n; i++) {
         p *= term;
         term = term + i;
      }
      cout << "Product: " << p << endl;
   }

   system("pause");
   return 0;
}

Related Solutions

Write a program in C or C++ that takes a number series of size n (n...
Write a program in C or C++ that takes a number series of size n (n integers) as input from the user, push all the numbers to the stack, and reverse the stack using recursion. Please note that this is not simply popping and printing the numbers, but the program should manipulate the stack to have the numbers stored in reverse order. In addition to the provided header file, the students can use the following function to print the content...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n...
(8%) Write a C/C++ program that takes an input (array) from 1 to n (say n = 50) and displays the string representations of those numbers with following conditions If the current number is divisible by 2, then print CSU If the current number is divisible by 5, then print SB If the current number is divisible by both 2 and 5, then print CSUSB If the number is neither divisible by 2 nor 5, then print the number Example:...
Write a program in C or in Java, that takes an integer value N from the...
Write a program in C or in Java, that takes an integer value N from the command line, generates N random points in the unit square, and computes the distance separating the closest pair of points. A unit square is a square with sides of length 1, at points (0, 0), (0, 1), (1, 0), and (1, 1). If you wish to avoid the command-line processing, you can just assume you will generate a fixed number of points, say between...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each...
Write a program in C (NOT C++ or C#) The program inputs 5 elements into each of 2 integer arrays. Multiply corresponding array elements, that is, arrayOne[0] * arrayTwo[0], etc. Save the product into a third array called prodArray[ ]. Display the product array.
In C++, write a function that takes in as inputs two arrays, foo and bar, and...
In C++, write a function that takes in as inputs two arrays, foo and bar, and their respective array sizes. The function should then output the concatenation of the two arrays as a singly linked list. You may assume that you are provided a singly linked list header file.
Write a C++ program that inputs three integers in the range [1..13] that represent a hand...
Write a C++ program that inputs three integers in the range [1..13] that represent a hand of three cards. Your program should output an English evaluation of the hand. In the output, cards will be described as follows: - 2–10 are described by the words for their numeric values: two, three, etc. - 1 is called an ace, 11 is called a jack, 12 is called a queen, and 13 is called a king. The evaluation of a hand is...
Write a program (O(n), where n is the number of words) that takes as input a...
Write a program (O(n), where n is the number of words) that takes as input a set of words and returns groups of anagrams for those words. Complete your code here Do not change anything in the test file. CPP File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); vector> findAnagrams(const vector& dict) { // Your code here... } Test File: #include #include #include #include using namespace std; vector> findAnagrams(const vector& dict); int main() { vector word_list...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming...
In python. Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming distance between two strings is the number of positions at which the corresponding symbols are different. The program should output an integer representing this distance. For example a = XXWWZZ b = ZZWWXX answer = 4 More examples: "Phone" and "PHOONE" = 3 "God" and "Dog" = 2 "Dog" and "House" = 4
Write a program which takes 3 inputs values as dimensions of a cuboid. Do the following-...
Write a program which takes 3 inputs values as dimensions of a cuboid. Do the following- 1. Verify it forms a cuboid (non zero, non negative and non-integer inputs). 2. Show the longest and shortest edges. 3. Calculate the surface area of the square made by the two short edges. 4. Calculate the volume of the cuboid. Refer the following to learn about the cuboid (generally this is called the domain knowledge) https://www.math-only-math.com/cuboid.html Volume and Surface Area of Cuboids and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT