Users Online

· Guests Online: 15

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

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

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

This C Program reads two integers & swap their values.
Here is source code of the C program to read two integers & swap their values. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* 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.
*/
#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;
}

$ cc pgm36.c
$ a.out
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

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.80 seconds
10,800,142 unique visits