18. Program to Swap Two Numbers

//Using temporary variable::

void main()
{
int a,b,temp;
printf("enter two no");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf(" after swapping no a=%b",a,b);

getch();
}

Comments

  1. /*Program to Swap Two Numbers*/
    #include
    #include
    void main()
    {
    int a,b,c;
    clrscr();
    printf("Enter value for A=");
    scanf("%d",&a);
    printf("Enter value for B=");
    scanf("%d",&b);
    c=a;
    a=b;
    b=c;
    printf("Swapped Values of A=%d, B=%d",a,b);
    getch();
    }

    ReplyDelete
  2. #include
    #include
    void main()
    {
    int a,b,temp;
    printf("enter two no");
    scanf("%d%d",&a,&b);
    temp=a;
    a=b;
    b=temp;
    printf(" after swapping no a=%b",a,b);

    getch();
    }

    ReplyDelete
  3. #include
    #include
    void main()
    {
    int x,y,z;
    clrscr();
    printf("\nEnter the value of two numbers");
    scanf("%d%d",&x,&y);
    z=x;
    x=y;
    y=z;
    printf("swapping no. are x is %d & y is %d",x,y);
    getch();
    }

    ReplyDelete

Post a Comment