Answers for "swapping of two numbers using function in c"

C
0

c program to swap two numbers using call by reference

#include <stdio.h>
 
void swap(int*, int*);
 
int main()
{
   int x, y;
 
   printf("Enter the value of x and yn");
   scanf("%d%d",&x,&y);
 
   printf("Before Swappingnx = %dny = %dn", x, y);
 
   swap(&x, &y); 
 
   printf("After Swappingnx = %dny = %dn", x, y);
 
   return 0;
}
 
void swap(int *a, int *b)
{
   int temp;
 
   temp = *b;
   *b = *a;
   *a = temp;   
}
Posted by: Guest on February-18-2021
0

c program for swapping of two numbers using temporary variable

#include <stdio.h>
int main()
{
    int a, b, temp;
    printf("enter the values of a and b: n");
    scanf("%d%d", &a, &b );
    printf("current values are:n a=%dn b=%dn", a, b);
    temp=a;
    a=b;
    b=temp;
    printf("After swapping:n a=%dn b=%dn", a, b);
}
Posted by: Guest on April-19-2021

Code answers related to "swapping of two numbers using function in c"

Code answers related to "C"

Browse Popular Code Answers by Language