Simple C Program Special Logic Tricks

8
2227

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

Previous articleAlibaba Reach 1 Million Users in UK – INFOGRAPHIC
Next articleHow To Win an iPad2
Olawale Daniel is a business builder and psychologist, a network marketing professional, a world-class motivational speaker, a successful internet entrepreneur and a digital media strategist interested in all things mobile and digital — start-ups, media, branding. He started TechAtLast back in 2010 as a platform to quench his thirst for latest technologies. As a motivational speaker and author, Olawale has published several motivational and personal development books and he's currently working on "SUCCESS AHEAD - Don't Quit" which is billed to hit the stand by Q4 of the year. He writes regularly on his personal website on motivation and personal lifestyle and tips for network marketing success, OlawaleDaniel.com. His latest book on How to Sponsor More People in Your Network Marketing Business is still one of the best sellers in its category. He's presently working as a Health and Wellness consultant at BURN SLIM TRIM Inc., a firm that helps people regain their perfect lifestyle through state-of-the-art recent discoveries way back from nature. He's also the brain behind FOBCourse, a business university for startup entrepreneurs in Africa.

8 COMMENTS

  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

Please enter your comment!
Please enter your name here

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