Ask 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, 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. 8 June, 08:38
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers