Develop a program that uses four signed, global, short variables A, B, C, D Initialize each variable A, B, C, D to a different positive one-digit value Somehow print the four values in order A B C D, space separated Print a newline character Reorder the values in the variables from the order A, B, C, D to B, C, D, A
A -> B
B -> C
C -> D
D -> A
Somehow print the four values in order A B C D, space separated
Hi,
Hope you are doing fine. I have coded the above question in C++. The logic is same irrespective of any language. All the conditions as per the question have been met. The code has been clearly explained using comments that have been highlighted in bold.
Program:
#include <iostream>
using namespace std;
//declaring global signed short int variables and
initializing them.
signed short int A=1,B=2,C=3,D=4;
int main()
{
//printing each variable, seperating them by
space
cout << A <<" "<<B<<"
"<<C<<" "<<D;
//printing a new line character
cout <<"\n";
//declaring local variables that will store
the values of A,B,C,D
signed short temp1,temp2,temp3,temp4;
//storing values of A, B, C, D into temp
variables
temp1=A;
temp2=B;
temp3=C;
temp4=D;
//changing the values of A, B, C, D using the
values in temp variables as per the order mentioned in the
question
A=temp2;
B=temp3;
C=temp4;
D=temp1;
//printing each variable, seperating them by
space
cout << A <<" "<<B<<"
"<<C<<" "<<D;
}
Executable code snippet:
Output:
Get Answers For Free
Most questions answered within 1 hours.