Write a program to swap two integers


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Write a program to swap of two numbers
// Eg: 2 3 -> 3 2, -4 6 -> 6 -4
#include
int main(){
    int a,b,c;
    printf("Enter first number:");              // input from user
    scanf("%d",&a);
    printf("Enter second number:");
    scanf("%d",&b);
    printf("Before swapping:%d %d\n",a,b);
    c = a;
    a = b;                                      // swapping using three variables
    b = c;
    printf("After swapping:%d %d\n",a,b);
    getch();
}

No comments:

Post a Comment