TechAtLast

//Swap Two Numbers In Single Statement Without Temp Variable

#include<iostream.h>

#include<conio.h>

int main ()

{

C Program Special Logic Tricks

//Swap Two Numbers In Single Statement Without Temp Variable

#include<iostream.h>

#include<conio.h>

int main ()

{

int a=1,b=2;

clrscr();

a=a+b-(b=a);

cout<<“A: “<<a<<” B: “<<b;

getch();

}

You Can Also Take Input Values For A And B Variables

May Be Your Question Is How This Statement Working ?

a=a+b-(b=a);

First Step a=1+2-(b=1); // Also Assign Values Of a To b

Then a=1+2-1

Now a=2, b=1

OshoGarg is a tech writer from latest tips and tricks blog who share tips on blogger.

More About Me

10 Responses

  1. I enjoy, lead to I found just what I used to be taking a look for. You have ended my four day long hunt! God Bless you man. Have a great day. Bye

  2. Wonderful goods from you, man. I have understand your stuff previous to and you’re just too great. I really like what you’ve acquired here, certainly like what you’re saying and the way in which you say it. You make it entertaining and you still take care of to keep it wise. I can not wait to read far more from you. This is really a terrific website.

  3. Hi..

    Anybody.. Could you please help me in the below logic..!

    A random array of elements is given. Your program needs to find all the sections(sequences) in the array that are in ascending order, find the sum of those sequences, then find the largest sum and print the largest sum along with the sequence of numbers. For example if the array is like

    4, 5, 6, 2, 1, 2, 3, 4, 12, 6, 4, 2, 1, 5, 8, 9

    Then ascending sequences in the given array are
    · 4,5,6 with sum 15
    · 1,2,3,4,12 with sum 22
    · 1,5,8,9 with sum 23

    So your program should print the sequence 1 5 8 9 and the sum 23, as it’s the largest sum of ascending sequences.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.