Swap Two Numbers

Posted By on September 26, 2014


Download PDF
Find Size of int, float, double and char of Your System

This program asks user to enter two numbers and this program will swap the value of these two numbers.

Source Code to Swap Two Numbers


#include <stdio.h>
int main(){
      float a, b, temp;
      printf("Enter value of a: ");
      scanf("%f",&a);
      printf("Enter value of b: ");
      scanf("%f",&b);
      temp = a;    /* Value of a is stored in variable temp */
      a = b;       /* Value of b is stored in variable a */
      b = temp;    /* Value of temp(which contains initial value of a) is stored in variable b*/
      printf("nAfter swapping, value of a = %.2fn", a);
      printf("After swapping, value of b = %.2f", b);
      return 0;
}

Output


Enter value of a: 1.20
Enter value of b: 2.45

After swapping, value of a = 2.45
After swapping, value of b = 1.2
Find Size of int, float, double and char of Your System

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com