Description: This C++ code is named Mystery because of confusion created by parameters (variables and arrays) sent by-value and by-reference. This is one of those C++ programming codes that are confusing and challenging. A function is called from main() and then some other function calls are made from that function.
#include <iostream>
using namespace std;
void mystery2(int t2[],int a2[],int n2,int k2)
{
for (int j=0;j<k2;j++)
t2[j]=a2[n2-k2+j];
}
void mystery3(int a3[],int n3,int k3)
{
for (int
i=n3-1;i>=k3;i--)
a3[i]=a3[i-k3];
}
void mystery4(int t3[],int a3[],int k3)
{
for (int i=0;i<k3;i++)
a3[i]=t3[i];
}
void mystery1(int a1[],int n1, int k1)
{
int temp[100];
if (k1>0){
mystery2(temp,a1,n1,k1);
mystery3(a1,n1,k1);
mystery4(temp,a1,k1);
}
}
int main()
{
int arr[5]={1,2,3,4,5};
mystery1(arr,5,3);
for (int i=0;i<5;i++)
cout<<arr[i]<<" ";
return 0;
}
No comments
Post a Comment