Question: Program: #include #include int count(int *a,int N); int main() { File *fptr; int a[10000]; int N=0; //Declare N fptr = fopen(C: umber1.dat,w); //Open the file

Program:

#include

#include

int count(int *a,int N);

int main()

{

File *fptr;

int a[10000];

int N=0; //Declare N

fptr = fopen("C:\ umber1.dat","w"); //Open the file

//Check if file is open

if((fptr = fopen("C:\ umber1.dat","r")) == NULL)

{

//Read integer

while(fread(a[N],*fptr))

{

//Increment the N by 1

N++;

}

// close the file

fclose(fptr);

//Display the number count

printf("Numbers in the file:",(N+1));//Total pairs

printf("Total pairs:",count(a,N));

}

//otherwise

else

//Display message

printf("Cannot open file.");

//stop

return 0;

}

//A function Definition

int count(int *a,int N)

{

//Clock varibales

clock_t start_t, end_t, total_t;

int i,j, k;

//Starting the clock

start_t = clock();

printf("Starting of the program, start_t =",start_t);

int counting = 0;

//Use three loops to find the sum of three

for (i = 0; i

for (j = i+1; j

for (k = j+1; k

{

//Display the sum

printf(a[i]+a[j]+a[k]);

print("\t");

//Count the pair

counting++;

}

//end of clock

end_t = clock();

//Display total running time..

total_t = (double)(end_t - start_t);

printf" Total Time:d",total_t);

//Return the pair

return counting;

}

Output:

Program: #include #include int count(int *a,int N); int main() { File *fptr;

By Using above Threesum program and output :

Write a C program the spawns a child process from the parent process. In the child process implement the above program. As we know, the Threesum algorithm has N-cubed order and hence takes a long time to complete (especially for larger files of numbers). Use the clock( ) function to compute the time it takes to run the program. Start the clock at the beginning of the program and end it at the end of the program, then compute the execution time. This may give a surprising result, especially for larger files of numbers as you wait for the program to execute. Then begin the clock inside (at the beginning) the child process and end it at the end of the child process. Compute the execution time of the child process and note it and the time of the parent process and note that. Try this with the C system wait( ) function (so the parent waits for the child to complete) and without the wait( ) function.

What do you think caused these results? Explain! make a table (and/or graph) of your results and then an objective analysis.

MAKE SURE The program must be written in C language and also include the output. Plz DONOT answer if the program doesn't run properly or any other language.

305 200 201 297 298 300 301 299 197 299 300 301 302 303 198 302 301 302 303 304 199 303 304 305 200 305 306 201 202 203 300 301 302 303 304 307 199 302 303 304 305 200 304 305 306 201 306 307 302 308 203 204 303 304 305 306 201 305 306 307 202 307 308 203 309 204 205 306 307 308 203 308 309 204 310 205 206 309 310 205 311 206 207 312 207 208 209 Total Time :0 Total pairs 192920

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!