I need to convert these two small program to c++ and provide with print screen f
ID: 3766535 • Letter: I
Question
I need to convert these two small program to c++ and provide with print screen for the out put .
void fun(int*p) // pass by refernce
{
int i;
for(i=0;i<=100;i++)
{
printf("%d",*p);
p++;
}
}
void main()
{
int arr[100] = {0,0};
int i ;
clock_t t;
float t= clock();
for(i=0;i<=10;i++)
{
fun(arr);
}
t=clock_t;
cout<"process reterned 0 (0x0) excution time:"<<((float))t/CLOCKS_PER_SEC<<"s"<<endl;
}
the second one :
void fun(int p[100]) pass by value
{
int i ;
for(i=0;i<=100;i++)
{
printf("%d",p[i]);
}
}
void main()
{
int arr[100]={0,0};
int i;
clock_t t;
t= clock();
for(i=0;i<=10;i++)
{
fun(arr);
t=clock_t;
cout<"process reterned 0 (0x0) excution time:"<<((float))t/CLOCKS_PER_SEC<<"s"<<endl;
}
}
the idea here to copmpare the time excution between two array one pass by value and the second one pass by reference in two separated program
Explanation / Answer
1.
#include<iostream>
using namespace std;
void fun(int*p);
int main()
{
int arr[100] = {0,0};
int i ;
clock_t t;
float t= clock();
for(i=0;i<=10;i++)
{
fun(arr);
}
t=clock_t;
cout<"process reterned 0 (0x0) excution time:"<<((float))t/CLOCKS_PER_SEC<<"s"<<endl;
}
void fun(int*p) // pass by refernce
{
int i;
for(i=0;i<=100;i++)
{
cout<<*p;
p++;
}
}
2.
#include<iostream>
using namespace std;
void fun(int p[100])
{
int i ;
for(i=0;i<=100;i++)
{
cout<<p[i];
}
}
int main()
{
int arr[100]={0,0};
int i;
clock_t t;
t= clock();
for(i=0;i<=10;i++)
{
fun(arr);
t=clock_t;
cout<"process reterned 0 (0x0) excution time:"<<((float))t/CLOCKS_PER_SEC<<"s"<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.