Sunday, 15 December 2013

C Program to Read Two Integers M and N & Swap their Values

#include < stdio.h>
void swap(float *ptr1, float  *ptr2);
 
void main()
{
    float m, n;
 
    printf("Enter the values of M and N \n");
    scanf("%f %f", &m, &n);
    printf("Before Swapping:M = %5.2ftN = %5.2f\n", m, n);
    swap(&m, &n);
    printf("After Swapping:M  = %5.2ftN = %5.2f\n", m, n);
}
/*  Function swap - to interchanges the contents of two items */
void swap(float *ptr1, float *ptr2)
{
    float temp;
 
    temp = *ptr1;
    *ptr1 = *ptr2;
    *ptr2 = temp;
}

Output

 Enter the values of M and N
 2   3 
Before Swapping:M =   2.00     N =   3.00 
After Swapping:M  =   3.00     N =   2.00 

For More Details Please Visit Ictjobs.info

No comments: