Ask Question
19 April, 19:01

Write a complete C program that obtains two integers from the user, saves them in the memory, and calls the function void swap (int * a, int * b) to swap the content of the two integers. The main function of your program should display the two integers before and after swapping.

+1
Answers (1)
  1. 19 April, 20:47
    0
    C program for swapping numbers

    #include

    void swap (int * num1, int * num2) / *Defining function for swapping the numbers*/

    {

    int temp; / *using third variable to store data of numbers*/

    temp = * num1;

    *num1 = * num2;

    *num2 = temp;

    }

    int main () / /driver function

    {

    int a, b;

    printf ("Enter the numbers for swapping/n"); //taking input

    scanf ("%d %d",&a,&b);

    printf ("The numbers before swapping is a = %d and b=%d / n", a, b);

    swap (&a, &b); //calling function for swaping

    printf ("The numbers after swapping is a=%d and b=%d", a, b);

    return 0;

    }

    Output

    Enter the numbers for swapping 3,4

    The numbers before swapping is a = 3 and b=4

    The numbers after swapping is a=4 and b=3
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a complete C program that obtains two integers from the user, saves them in the memory, and calls the function void swap (int * a, ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers