Saturday, March 18, 2023

C Programming. Program to swap two numbers using macros.

 Program to swap two numbers using macros.

// Program to swap two numbers using macros.

#include<stdio.h>

#define swap(a, b) int t=a; a=b; b=t;

int main() {
    int a, b;
    printf("Enter two numbers : ");
    scanf("%d%d", &a, &b);
    printf("Before swapping a = %d, b = %d\n", a, b);
    swap(a, b);
    printf("After swapping a = %d, b = %d", a, b);
    return 0;
}

Output :

Enter two numbers : 5 7 Before swapping a = 5, b = 7 After swapping a = 7, b = 5

No comments:

Post a Comment

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...