by Dinesh Thakur

In this program user ask to swap the numbers. User declares the variables for containing the value in it. User define the method with arguments or parameter (*int, int*). Then user assign the value to each variables then print the message to before and after value phase in each variable. Next move to call the function that declares the early in the program. Using swapping method as usual. Display the result on the screen as output.

Problem Statement

This is C program that asks user to swap two numbers.

  1. Declare the variables.
  2. Using method.
  3. Display the result on the screen.

Here is C source code to swap the two numbers. The output of this program shown below. 

#include<stdio.h>
int swaping(int *,int *);
main()
{
    int a,b;
    clrscr();
    a=10;
    b=20;
    printf ( "Before swaping a = %d & b = %d",a,b);
    swaping(&a,&b);
    printf("\nAfter swaping a = %d & b = %d",a,b);
    getch();
  }
  int swaping(int * a, int * b)
  {
    *a=*a+*b;
    *b=*a-*b;
    *a=*a-*b;
  }
 C Program Swap Two Number