Question

In: Computer Science

Write using C++ a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard...

Write using C++

a) Inputs two 1D arrays of doubles A[i] and B[i] from the keyboard with a maximum size of 1000. The elements are input one at time alternating between A and B (ie A[0],B[0],A[1],B[1], …, A[i],B[i]) until a value of less than -1.0e6 is input or i >= 1000. Then the program continues to part b).

b) Calculates C = A + B, where + is vector addition (ie C[i] = A[i] + B[i]), and prints each element of C to the screen.

c) Calculates the minimum value of A[i] and prints it to the screen.

d) Adds the elements of B[i] and prints the result to the screen.

e) Multiplies the elements of A[i] and prints the result to the screen.

f) Using an infinite loop, determines and prints out the positive integer value of k for which the expression abs(x^k / k!) is less than 1.0e-9 where x = A[0].

Solutions

Expert Solution

#include <bits/stdc++.h>

using namespace std;

double factorial(int n)

{  

    return (n==1 || n==0) ? 1: n * factorial(n - 1);  

}

int main() {

    double A[1005],B[1005],C[1005],minv=INT_MAX,sumb=0,multia=1;

    int size=0;

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

    {

        cout<<"Enter the input for A array=";

        cin>>A[i];

if(A[i]<-1000000)

        break;

        if(A[i]<minv)

        minv=A[i];

       multia=multia*A[i];

       

        cout<<endl<<"Enter the input for B array=";

        cin>>B[i];

        if(B[i]<-1000000)

        break;

        sumb=sumb+B[i];

        cout<<endl;

        

        size++;

    }

cout<<endl<<"Values of vector of C=";

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

   {

       C[i]=A[i]+B[i];

       cout<<C[i]<<" ";

   }

   cout<<endl<<"Minimum value of A array ="<<minv<<endl;

   cout<<"Sum of B array ="<<sumb<<endl;

   cout<<"Multiplication of array of A ="<<multia<<endl;

   double x,k;

   x=A[0];

   k=1;

   while((pow(x,k)/factorial(k))>0.000000001)

   {

       k++;

   }

cout<<" k="<<k;

}


Related Solutions

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 (cin) a word from the keyboard and generates several different...
Write a C++ program that inputs (cin) a word from the keyboard and generates several different scrambles of the word without using vectors. The input word can be from 4 to 10 letters in length. The number of scrambles produced depends on the number of letters in the word. e.g. the 4 letter word “lose” would have 4 different scrambles produced and the seven letter word “edition” would have seven different scrambles. Here is a candidate example:      Input: FLOOR...
Using c++, write a program that reads a sequence of characters from the keyboard (one at...
Using c++, write a program that reads a sequence of characters from the keyboard (one at a time) and creates a string including the distinct characters entered and displays the string on the screen. The input terminates once the user enters a white-space character or the user has entered 50 distinct characters. Do not use C-Strings. 2. Use the following function to append character “ch” to the string “s”: s.push_back(ch); 3. Read the input characters one by one, i.e. do...
write a python program that inputs 10 integer values from the keyboard and then displays their...
write a python program that inputs 10 integer values from the keyboard and then displays their sum. use for loop
Using C++ Write a program that reads a text from the keyboard until the user presses...
Using C++ Write a program that reads a text from the keyboard until the user presses the “Enter” key. Your program must count the number of uppercase alphabets (A through Z), lowercase alphabets (a through z), digits (0 through 9) and any other characters. The other character count value should NOT include the “Enter” key. Display the count on the screen. You must use the in-built C++ character I/O functions in this program.
Write a program that takes two integer arrays a and b of size n from the...
Write a program that takes two integer arrays a and b of size n from the user, the use a method product to find the product of a and b and return the results after storing them in an array c, then prints the returned results to the screen. (Note: c[i] = a[i] * b[i], for i = 0, ..., n-1) Sample Output: Enter the size of your arrays: 5 Enter the integer values of the first array a: 1...
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write a program of Binary Search in C++ by using function and arrays with the explanation.
Write a program of Binary Search in C++ by using function and arrays with the explanation.
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT