Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using an inline function perform the calculation in which you cr

ID: 3746123 • Letter: W

Question

Write a program using an inline function perform the calculation in which you create a const whose value is determined at runtime by reading the time when the program starts (Hint: use the <ctime> standard header). In a separate function, have the program create two arrays of 10 000 doubles. Initialize the first array with sequential integral values starting with 100, and initialize the second array with the same numbers, but in reverse order (i.e., the first array would contain 100, 101, 102… while the second array contains 10099, 10098, 10097…). Loop through both arrays using a single loop, multiply the corresponding array elements from each array together, and display the result. Read the time when the program completes the multiplication, then compute and display the elapsed time. (in c++)

Explanation / Answer

#include<iostream>

#include<ctime>

using namespace std;

int main()

{

    // create an array of size 10000

    double *arr1 = new double[10000];

    double *arr2 = new double[10000];

   

    int i;

   

    double start = time(NULL);

   

    // add the elements in array

    for( i = 0 ; i < 10000 ; i++ )

    {

        arr1[i] = 100 + i;

       

        arr2[i] = 10099 - i;

    }

   

    for( i = 0 ; i < 10000 ; i++ )

        int x = arr1[i] * arr2[i];

   

    double end = time(NULL);

   

    // calculate time elapsed

    double time_taken = (double)(end - start);

   

    cout<<"Time Taken : "<<time_taken;

   

    return 0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote