Simple C Program Special Logic Tricks - Technology Blog
+234 816 619 6130 Saturday - Sep 24, 2016

Simple C Program Special Logic Tricks


//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.

©2015 TechAtLast Int'l Media, Inc. All Rights Reserved.
8 comments
  1. Mayur

    December 6, 2011 at 11:37 am

    An awesome logic !!
    Thanks for share 🙂

    Reply
  2. Jack

    November 29, 2012 at 6:11 pm

    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

    Reply
  3. Wilber

    December 1, 2012 at 5:08 am

    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.

    Reply
  4. Tara chand

    January 15, 2013 at 7:14 pm

    really its very fantastic logic

    Can u suggest a site for that type of logic

    Reply
    • Olukunle Moses

      January 29, 2013 at 8:44 pm

      You can search for Osho Garg on Google….

      Reply
  5. Anil

    November 28, 2014 at 7:09 am

    Wow, awesome logic, was fun to try it on C compiler, thanks again.

    Reply
  6. Usha

    January 22, 2015 at 12:23 pm

    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.

    Reply

Leave a Reply

Your email address will not be published.

Predefined Skins

Primary Color

Background Color

Example Patterns

demo demo demo demo demo demo demo demo demo demo