Example(s):Palindrome, prime, armstrong, "linear search", reverse etc.
Example(s):1575, 1632, 1539 (Only one at a time)
Login
[lwa]
Solved Problem
#CPP#7684
Problem Statement - Output writing using structure copy and strcat use
struct Play {char Arr[20];int n;};
int main()
{
struct Play P={"JUDO",2};
P.Arr[0]='L';
P.n+=2;
cout<<P.Arr<<"#"<<P.n<<endl;
Play R = P;
R.Arr[0]='S';R.Arr[1]='O';
strcat(R.Arr,"KU");
R.n-=3;
cout<<R.Arr<<"#"<<R.n<<endl;
return 0;
}
Write the output of the above program. Assume that required header files are present.
Solution
TC++ #7684
Run Output
LUDO#40
SODOKU#1
struct Play P={“JUDO”,2}; //structure initialised with Arr[] content as JUDO and n as 2 P.Arr[0]=’L’; //JUDO becomes LUDO as 0th character changed P.n+=2; //n becomes 4 as 2 is added to previous value cout<<P.Arr<<“#”<<P.n<<endl; //LUDO#4 printed Play R = P; //Another copy of structure object made as R which will have final values as contained in P R.Arr[0]=’S’;R.Arr[1]=’O’; //R’s arr[] now becomes SUDO strcat(R.Arr,”KU”); //Additional KU is concatenated to SUDO making it SODUKU R.n-=3; //R’s n us reduced by 3 making it 1 cout<<R.Arr<<“#”<<R.n<<endl; //SODOKU#1 is printed