Write a program to swap two values, using cell-by-value method.
1. Ans.//Call by Value Example – Swapping 2 numbers using Call by Value
2. #include
3.
4.
5. void swap(int, int);
6.
7. int main()
8. {
9. int x, y;
10.
11. printf(“Enter the value of x and y\n”);
12. scanf(“%d%d”,&x,&y);
13.
14. printf(“Before Swapping\nx = %d\ny = %d\n”, x, y);
15.
16. swap(x, y);
17.
18. printf(“After Swapping\nx = %d\ny = %d\n”, x, y);
19.
20. return 0;
21. }
22.
23. void swap(int a, int b)
24. {
25. int temp;
26.
27. temp = b;
28. b = a;
29. a = temp;
30. printf(“Values of a and b is %d %d\n”,a,b);
31. }