/ Undifined / 24 - WAP to swap two elements using the concept of pointers.

24 - WAP to swap two elements using the concept of pointers.

#include<stdio.h>
 
void swap(int *num1, int *num2) {
   int temp;
   temp = *num1;
   *num1 = *num2;
   *num2 = temp;
}
 
int main() {
   int num1, num2;
 
   printf("\nEnter the first number : ");
   scanf("%d", &num1);
   printf("\nEnter the Second number : ");
   scanf("%d", &num2);
 
   swap(&num1, &num2);
 
   printf("\nFirst number  : %d", num1);
   printf("\nSecond number : %d", num2);
 
   return (0);
}
Output 
Enter the first number  : 12
Enter the Second number : 22
First number  : 22
Second number : 12

about author

Blogger Sens it website about blogger templates and blogger widgets you can find us on social media
Previous Post :Go to tne previous Post
Next Post:Go to tne Next Post

No comments:

Post a Comment