Write a C-program Swap Two Number using Pointer and Function:

Swap Two Number using Pointer and Function:

 Tips:                                                                                              

 1.Take three variables.
 2.Take two inputs from user.
 3.Assign variables one by one each other.
 4.Take pointer variable and address to swap.

Code:

void add(int *,int *);
void main()
{
    int a,b;
    printf("Enter two number two swap:\n");
    scanf("%d%d",&a,&b);
    printf("\nyou decide:\n a=%d and b=%d",a,b);
    add(&a,&b);
    printf("\nThe swap number is: a=%d and b=%d",a,b);
    getch();
}
void add(int *x, int *y)
{
    int s;
    s=*x;
    *x=*y;
    *y=s;
}

Output:

 

Please comment!

Comments

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Find Factorial using Recursion | C Program: