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.


by

Tags:

Comments

10 responses to “Simple C Program Special Logic Tricks”

  1. Mayur Avatar
    Mayur

    An awesome logic !!
    Thanks for share 馃檪

  2. Jack Avatar
    Jack

    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

  3. Wilber Avatar
    Wilber

    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.

  4. Tara chand Avatar
    Tara chand

    really its very fantastic logic

    Can u suggest a site for that type of logic

    1. Olukunle Moses Avatar
      Olukunle Moses

      You can search for Osho Garg on Google….

  5. Anil Avatar

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

    1. Olawale Daniel Avatar

      You’re welcome here Anil.

  6. Usha Avatar
    Usha

    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鈥檚 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.