Two numbers are input through the keyboard into two locations C and D. Write an algorithm and draw flowchart to interchange the contents of C and D.
Answers
Answer:
Void main()
{
Int c,d,e;
Clrscr();
Printf(“\nEnter the number at locations C:”);
Scanf(“%d”,&c);
Printf(“\nEnter the number at locations D:”)
Scanf(“%d”,&d);
e=c;
c=d;
d=e;
Printf(“\nNew number at locations C=%d”,c);
Printf(“\nNew number at locations D=%d”,d);
Printf(“\n\n\n\n\nPress any key to exit”);
Getch();
algorithm to interchange contents of C and D
Explanation:
Two numbers are input through the keyboard into two locations C and D.
algorithm to interchange the contents of C and D
c = int(input("Enter Number to store at location C: "))
d = int(input("Enter Number to store at location D: "))
# interchanging their contents
e = c
c = d
d = e
# Printing C and D after interchanging their contents
print("\nAfter Interchanging content of C and D\nC: {}, D: {}".format(c,d))
hence, this is an algorithm to interchange contents of C and D