Wednesday 3 August 2016

  • SWAPPING TO NUMBERS WITHOUT TAKING ANY TEMPORARY VARIABLE

    /*We generally swap or interchange to variables by taking a temporary variable.Here is a simple program for swapping to numbers without using any intermediate variable*/

    Language=C

    #include<stdio.h>
    int main()
    {
        int a,b;

        printf( "Enter the value of a and b=" );
        scanf( "%d%d",&a,&b );

        printf( "a and b before swapping\n" );
        printf( "%d %d\n",a,b );

        a = a+b;
        b = a-b;
        a = a-b;

        printf( "a and b after swapping\n" );
        printf( "%d %d\n",a,b );

        return 0;
    }

No comments:

Post a Comment

Kruskal Algorithm

Minimum Cost Spanning Tree By Kruskal Algorithm using priority_queue in c++ #include<bits/stdc++.h> using namespace std; typedef p...