In this example, We are going to swap two numbers. For interchanging two number we use a third variable for temporally storing value.
Program to swap two numbers in c
#include<stdio.h>
void main()
{
int a,b,temp;
printf("Enter any number : ");
scanf("%d",&a);
printf("Enter any other number : ");
scanf("%d",&b);
printf(" ** Before swapping ** \n");
printf("a = %d \n",a);
printf("b = %d \n",b);
temp = a;
a = b;
b = temp;
printf(" ** After swapping ** \n");
printf("a = %d \n",a);
printf("b = %d \n",b);
}
Output
Enter any number : 10
Enter any other number : 20
** Before swapping **
a = 10
b = 20
** After swapping **
a = 20
b = 10
Introduction of C and Hello World Program
C program to Addition of two numbers
C program to find Area of Triangle
C program to find Area of Circle
C program to find Area of Rectangle
C program to Calculate Simple Interest
C program to Calculate Compound Interest