Here is my attempt, could you look over it and tell me what I am doing wrong?
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;
void add(float[],float[],float[]);
int main()
{
float a[500000000],b[500000000],c[500000000];
for(int count =0; count<500000000;count++)
{
a[count]=rand();
b[count]=rand();
}
add(a,b,c);
return 0;
}
void add(float x[],float y[],float z[])
{
time_t begin,end;
float d=10;
float e=6;
int total=0;
for(long countk=0;countk<500000000;countk++)
{
z[countk]=0;
}
for(int j=0;j<10;j++)//test the loop ten time to get a more
accerate executing
//time
{
begin = time(NULL);//sequence of when the time begins
for(int county=0;county<500000000;county++)
{
z[county]=0;
}
for(long countu =1; countu<500000000;countu++)
{
z[countu]=x[countu]+y[countu];
end = time(NULL);//how long it took for the loop to finish
}
cout<<"time for loop is "<<end-begin<<"seconds"<<endl;
total=total+end-begin;
cout<<"total="<<total<<endl;
}//end first loop
cout<<"time for exexcuting c=a+b is"
<<500000000/(total*pow(d,6))<<endl;
}
The program should output this:
hours since January 1, 1970 first = -4196164
hours since January 1, 1970 second = 1100010441
time for the loop is 13 seconds
total = 13
hours since January 1, 1970 second = 1100010454
time for the loop is 13 seconds
total = 26
hours since January 1, 1970 second = 1100010467
time for the loop is 13 seconds
total = 39
hours since January 1, 1970 second = 1100010480
time for the loop is 13 seconds
total = 52
hours since January 1, 1970 second = 1100010493
time for the loop is 13 seconds
total = 65
hours since January 1, 1970 second = 1100010506
time for the loop is 13 seconds
total = 78
hours since January 1, 1970 second = 1100010519
time for the loop is 13 seconds
total = 91
hours since January 1, 1970 second = 1100010532
time for the loop is 13 seconds
total = 104
hours since January 1, 1970 second = 1100010545
time for the loop is 13 seconds
total = 117
hours since January 1, 1970 second = 1100010558
time for the loop is 13 seconds
total = 130
time for executing the sum of 1 to 50000