In: Computer Science
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].
#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;
}