Question
Description; Threesum.cpp program reads a file of numbers and forms a sequence of sums of three numbers in the following manner: (1st + 2nd +
Description;Threesum.cpp program reads a file of numbers and forms a sequence of sums of three numbers in the following manner: (1st + 2nd + 3rd), (1st + 2nd + 4th), ...,(1st + 2nd + nth), (1st + 3rd + 4th), ...,(1st + 3rd + nth), ...,(1st + (n-1)th + nth), (2nd + 3rd + 4th), ...,((n-2)th + (n-1)th + nth). It can be shown that this is an O(n3) algorithm, and hence a slower process.
Program:
//Header File Declaration
#include
#include
#include
//A function Defination
long int count(long int *a)
{
//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 = %ld ", start_t);
int N = 10000;
int counting = 0;
for (i = 0; i
for (j = i+1; j
for (k = j+1; k
if ((a[i]+a[j]+a[k]) == 0)
{
printf("%ld\t%ld\t%ld",a[i], a[j], a[k]);
counting++;
} //end of clock end_t = clock();
//Display total running time..
total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
return counting;
}
//Starting of main function
int main() { FILE *fp;
char filename[15];
char ch;
long int arr[10000], i = 0;
//opening the file..
fp = fopen("numbers1.dat","r");
if (fp == NULL)
{
printf("Cannot open file ");
exit(0);
}
ch = fgetc(fp);
//reading the data from the file..
while(i
arr[i]=fgetc(fp);
++i; }
printf(" ");
printf("%ld ", count(&arr[0]));
printf(" ");
return 0;
}
Output:
A written description of the program.
written analysis of the program with different size data files. This should include a written analysis of the data gathered and tables and charts showing the data.
1213 14 15 16 17 18 19 20 2112 13 14 15 16 17 18 19 20 2112 13 14 15 16 17 18 19 20 1213141516 37 18 19 20 21121314151617181920 ] 14 is i6 17 IB 19 20 2112 13 1415 16171019202112 13 14 SI6 17 18 19 20 2112 IJ 141S 16 17 10 19 20 2112 13 14 15 16 17 18 19 14 1s id 17 10 19 20 2111114 is is 17 ss 19 20 21 12 13 14 1S 16 17 19 20 2112 13 141S 161710 L9282112 13 14 15 16 17 18 112 13 14 15 16 17 10 13 20 211233 14 1s 16 17 1s 19 20 2112 13 141s is 1.71019282112 13 14 s s 17 1s 39 2e 211213 14 s s1710 13 282112 13 14 s s 17181920211213 14 15 30 17 10 19 20 2112 13 14 ste17SS 19 20 2112 13 14 ss 16 17 10282132 13 14 IS 36 17 1 20211113 14 3S 16 17 19 20 2111114 15 16 17 10 19 20 2112 13 14 15 IS 17 IS 19 20 2112 131415 16 17 3B 19 20 2112 13 14 ssr 2112 13 14 Is i6 171019 28 2112 13141s i6 17 ll 19 20 2112 IJ 14 LS 16 17 10 19 20 2112 13141516 2718 19 20 2112 13 14 15 16 17 2112 13 34 as is 17 as 19 28 21 12 13 14 s s17us282112 13 14 s s 9 2e 2112 13 14 15 16 Ly as 13 20 2112 13 14 15 16 282112 13 14 15 16 17 1.s 12 2e 2112 13 14 ssrs1925 2112 13 14 s 17 1B 28 2112 33 14 15 IS 37S392S 2112 13 341s 16 1.7 17 20 2112 13 14 15 16 37 15 19202112 13 141s 16 17 a19 20 2112 13 14 s s r 15 3202112 13 14 15 IS 17181970 2112 13 14 15 10 III 19292112 131415 17 1B 19 20 2112 13 1415 10 17 18 19 20 2112 13 14 S16 17 IS 19 20 2112 IJ 14 IS 16171019 20 2112 13 14 1510 18 19 20 2112 IJ 141s i6 17 18 19 20 2112 13 14 s16 17 18 19 20 2112 LI S4 SS 16 17 18 19 20 2112 13 14 s sir is 19 20 2112 13 1415 16 stu:-/chew. solutionsStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started