Pages

Wednesday, June 15, 2016

C program to swap values of two variables using third variable.

#include<stdio.h>
int main()
{
int a,b,c;

printf("Enter number1:");
scanf("%d",&a);

printf("Enter number2:");
scanf("%d",&b);

c = a;  //assigning value to temporary variable
a = b;
b = c;

printf("Value in number1 is %d\n",a);
printf("Value in number2 is %d",b);
return 0;
}

Output of program

Enter number1:5
Enter number2:10
Value in number1 is 10
Value in number2 is 5

No comments:

Post a Comment