Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Program Threesum_C.c
- **
- ** Counts the occurances of a specified number in an array.
- **
- **
- */
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- long int count(long int *a); // prototype function
- int main()
- {
- long int arr[10000], i=0;
- int value;
- clock_t start_t, end_t, total_t;
- FILE *fp;
- fp = fopen("numbers1.dat", "r");
- if ((fp = fopen ("numbers1.dat", "r")) == NULL)
- return 1;
- start_t = clock();
- printf("Starting of the program: = %ld\n", start_t);
- fscanf(fp,"%d", &arr[i]);
- while(i < 10000)
- {
- fscanf(fp,"%d", &arr[i]);
- printf("%d", count(&arr[0]));
- ++i;
- }
- fclose(fp);
- end_t = clock();
- total_t = (double)(end_t - start_t) / CLOCKS_PER_SEC;
- printf("Total time taken by CPU: %f\n", total_t );
- return 0;
- }
- long int count(long int *a)
- { int N = 10000;
- int counting = 0;
- for (int i = 0; i < N-2; i++)
- for (int j = i+1; j < N-1; j++)
- for (int k = j+1; k < N; k++)
- if ((a[i]+a[j]+a[k]) == 0)
- {
- counting++;
- printf("Triplet Found : %d, %d, %d", a[i], a[j], a[k]);
- }
- return counting;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement