Tuesday 18 October 2016

C Program to Swap two values or numbers using third varriable

This is a C program to swap two variable values(a,b). This is done using a third variable(c).

Code: 
#include<stdio.h>
#include<conio.h>
void main()
{int a,b,c;
    printf(" \t\t\t\tSwapping the values\n");
    printf("Enter value of a ");
    scanf("%d",&a);
    printf("Enter value of b ");
    scanf("%d",&b);
    c=a;
    a=b;
    b=c;
    printf("\n\nAfter Swapping: \n\nValue of a = %d and value of b = %d",a,b);
    getch();
}

Output:

Here Code blocks & gcc compiler is used for the programming.

No comments:

Post a Comment