swap numbers using call by reference in C program
#include#include void swaping(int *x, int *y); int main() { int n1,n2; printf("Enter first number (n1) : "); scanf("%d",&n1); printf("Enter second number (n2) : "); scanf("%d",&n2); printf("\nBefore swapping values:"); printf("\n\tn1=%d \n\tn2=%d",n1,n2); swaping(&n1,&n2); printf("\nAfter swapping values:"); printf("\n\tn1=%d \n\tn2=%d",n1,n2); getch(); return 0; } void swaping(int *x, int *y) { int z; z=*x; *x=*y; *y=z; }
No comments:
Post a Comment