//Include the header files #include<iostream> #include<string> #include<fstream>
ID: 3827805 • Letter: #
Question
//Include the header files
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
//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();
cout<<"Starting of the program, start_t ="<<start_t<<endl;
int counting = 0;
//Use three loops to find the sum of three
for (i = 0; i <= N; ++i)
for (j = i+1; j <= N; ++j)
for (k = j+1; k <= N; ++k)
{
//Display the sum
cout<<(a[i]+a[j]+a[k])<<" ";
//Count the pair
counting++;
}
//end of clock
end_t = clock();
//Display total running time..
total_t = (double)(end_t - start_t);
cout<<" Total Time:"<<total_t<<endl;
//Return the pair
return counting;
}
//Starting of main function
int main()
{
//Declare file pointer
ifstream fid;
//Declare array a of type int
int a[10000];
//Declare N
int N=0;
//Open the file
fid.open("numbers1.dat");
//Check if file is open
if(fid.is_open())
{
//Read integer
while(fid>>a[N])
{
//Increment the N by 1
N++;
}
//Close the file
fid.close();
//Display the number count
cout<<"Numbers in the file:"<<(N+1)<<endl;
//Total pairs
cout<<"Total pairs:"<<count(a,N)<<endl;
}
//otherwise
else
//Display message
cout<<"Cannot open file."<<endl;
//stop
return 0;
}
OUTPUT:
Convert the program to standard C and explain the program.
Plz make sure just convert the program don't change anything else.
Sample input file: numbers!.dat-Notepad File Edit Format View Help 12345678910 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 6162 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 rm Ln 1, Col 1 000000000 234567891 999999999 123456789 888888888 123456789 0777777777 P11234567895 H-96666666661 123456789 Pe 5555555554 |y-71234567891 : N at 6 4 4 4 4 4 4 4 4 4 3 1234567890 For-5333333333 u-1. 41234567892 it-32222222221 e-m|E| 123456789 p-n-le- 1 | le 2 1 1 1 1 1 1 1 1 1 0 E 11234567891Explanation / Answer
Source code in c: just changed the program to c .
//Include the header files
#include<stdio.h>
#include<string.h>
int count(int *a,int N);
int main()
{
File *fptr;
//Declare array a of type int
int a[10000];
//Declare N
int N=0;
//Open the file
fptr = fopen("C: umber1.dat","w");
//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 <= N; ++i)
for (j = i+1; j <= N; ++j)
for (k = j+1; k <= N; ++k)
{
//Display the sum
printf(a[i]+a[j]+a[k]);
print(" ");
//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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.