Ask Question
27 May, 22:31

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.

+4
Answers (1)
  1. 28 May, 01:23
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers