Answers for "swap two numbers using pointers"

2

swap two numbers using pointers

#include<stdio.h>

#include<conio.h>

void swap(int *a,int *b);

void main()

{

int a = 20;

int b = 30;

printf("Before swapped: a = %d and b = %d\n",a,b);

swap(&a,&b);

printf("Swapped result: a = %d and b = %d\n",a,b);

getch();

}

void swap(int *a, int *b)

{

int temp;

temp = *a;

*a = *b;

*b = temp;

}
Posted by: Guest on March-18-2021
0

Swapping two numbers using Pointers

#include <stdio.h>
void swapnum(int *num1, int *num2)
{
   int tempnum;

   tempnum = *num1;
   *num1 = *num2;
   *num2 = tempnum;
}
int main( )
{
   int v1 = 11, v2 = 77 ;
   printf("Before swapping:");
   printf("\nValue of v1 is: %d", v1);
   printf("\nValue of v2 is: %d", v2);

   /*calling swap function*/
   swapnum( &v1, &v2 );

   printf("\nAfter swapping:");
   printf("\nValue of v1 is: %d", v1);
   printf("\nValue of v2 is: %d", v2);
}
Posted by: Guest on August-23-2021
2

swap two numbers using pointers

#include<stdio.h>

#include<conio.h>

void swap(int *a,int *b);

void main()

{

int a = 20;

int b = 30;

printf("Before swapped: a = %d and b = %d\n",a,b);

swap(&a,&b);

printf("Swapped result: a = %d and b = %d\n",a,b);

getch();

}

void swap(int *a, int *b)

{

int temp;

temp = *a;

*a = *b;

*b = temp;

}
Posted by: Guest on March-18-2021
0

Swapping two numbers using Pointers

#include <stdio.h>
void swapnum(int *num1, int *num2)
{
   int tempnum;

   tempnum = *num1;
   *num1 = *num2;
   *num2 = tempnum;
}
int main( )
{
   int v1 = 11, v2 = 77 ;
   printf("Before swapping:");
   printf("\nValue of v1 is: %d", v1);
   printf("\nValue of v2 is: %d", v2);

   /*calling swap function*/
   swapnum( &v1, &v2 );

   printf("\nAfter swapping:");
   printf("\nValue of v1 is: %d", v1);
   printf("\nValue of v2 is: %d", v2);
}
Posted by: Guest on August-23-2021

Code answers related to "swap two numbers using pointers"

Browse Popular Code Answers by Language