Pages

Sunday, 28 January 2018

Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

/* This program takes 2 digits and stores them in two location, then interchanges
the location of the numbers.*/
#include<stdio.h>
#include<conio.h>
int main ()
{
    /*declaring veriables*/
    int C,D, temp;
  
    /*prompt to take and taking input*/
    printf("   Please enter the number to store in location C: ");
    scanf("%d",&C);
    printf("\n   Now enter the number to store in location D: ");
    scanf("%d",&D);
  
    /*calculations*/
    temp = C;
    C = D;
    D = temp;
  
    /*showing results*/
    printf("\n   After Interchanging: ");
    printf("\n   __________________");
    printf("\n\n    Now number stored in location C is: %d\n",C);
    printf("\n    and the number stored in location D is: %d ",D);
    getche();
    return 0;
}