Sunday, 24 April 2022

1. Write a user defined function which will swap the values of two variables declared locally in the main program.

 


#include<stdio.h>
#include<conio.h>

int swap(int * , int *);

void main()
{
    int x , y;
    clrscr();

    printf("enter 1st number: ");
    scanf("%d",&x);

    printf("enter 2nd number: ");
    scanf("%d",&y);

    swap(&x,&y);

    printf("\n1st number after swap: %d",x);
    printf("\n2nd number after swap: %d",y);
    getch();
}

int swap(int *a, int *b)
{
    int c;

    c = *a;
    *a = *b;
    *b = c;

    return 0;
}

/*  output:

enter 1st number: 12
enter 2nd number: 13                                                            
                                                                               
1st number after swap: 13                                                      
2nd number after swap: 12                                                      
                                                                               
*/

No comments:

Post a Comment

python programs

1. sum of two number