C program to swap between 2 numbers

/* Write a C program to read two integers M and N *  * and to swap their values. Use a user-defined   *  * function for swapping. Output ...


/* Write a C program to read two integers M and N *
 * and to swap their values. Use a user-defined   *
 * function for swapping. Output the values of    *
 * M and N before and after swapping with suitable*
 * mesages                                       */

#include <stdio.h>
#include <conio.h>

void main()
{
  float M,N;

  void swap(float *ptr1, float  *ptr2 );  /* Function Declaration */

  printf("Enter the values of M and N\n");
  scanf("%f %f", &M, &N);

  printf ("Before Swapping:M = %5.2f\tN = %5.2f\n", M,N);
  swap(&M, &N);

  printf ("After Swapping:M  = %5.2f\tN = %5.2f\n", M,N);

}     /* End of main() */

/* Function swap - to interchanges teh contents of two items*/
void swap(float *ptr1, float *ptr2 )
{
   float temp;
   temp=*ptr1;
   *ptr1=*ptr2;
   *ptr2=temp;

} /* End of Function */


/* ----------------------------------------
Output
Enter the values of M and N
32 29
Before Swapping:M = 32.00       N = 29.00
After Swapping:M  = 29.00       N = 32.00
------------------------------------------*/



Related

C TUTORIAL 5859163959913997039

Post a Comment

emo-but-icon

Search Here

Popular query

Follow Us

Ads By Google

Get free Update

Enter your email address:

E-mail verification is must for complete subscription

Delivered by FeedBurner

Circle AFS on Google Plus!

Follow AFS Google+ page
 

Side Ads

DMCA protected
Information, images and the content on this blog is Copyright ©AFS2011-2018. Please do not copy Any content for commercial purpose else we have to take a legal action. Thanks !!

Total Pageviews

Recent

free counters
 

Connect Us

Speech by ReadSpeaker

item