Translate

Thursday, April 30, 2020

C Program to swap two numbers without using third(temporary) variable.



    /*C Program to swap two numbers without third variable*/
    In C we have two techniques to swap the number
    1. Without using third variable
    2. Using third variable

    1. Without using third variable swap the number:


    #include<stdio.h>

    #include<conio.h>
    void main()
    {
        int a, b;
        printf("Enter First number in a = ");
        scanf("%d",&a);
        printf("Enter Second number in b = ");
        scanf("%d",&b);
        a= a+b;
        b=a-b;
        a=a-b;
        printf("\nafter swaping the value of a = %d", a);
        printf("\nafter swaping the value of b = %d", b);
        getch();
    }

    Output:


    No comments:

    Post a Comment

    C program to make a calculator using the switch statement.

    /*perform arithmetic calculation on integers in C language*/ #include<stdio.h> #include<conio.h> void main() {     char op;     ...