C++ Program to Swap Two Numbers

53
476

C++ Program to Swap Two Numbers
This example contains two different techniques to swap numbers in C programming. The first program uses temporary variable to swap numbers, whereas the second program doesn’t use temporary variables.

Table of Contents

Programe :

#include <iostream>
using namespace std;

int main()
{
int a = 7, b = 10, temp;

cout << “Before swapping.” << endl;
cout << “a = ” << a << “, b = ” << b << endl;

temp = a;
a = b;
b = temp;

cout << “\nAfter swapping.” << endl;
cout << “a = ” << a << “, b = ” << b << endl;

return 0;
}

OutPut :

Before swapping.
a = 7, b = 10

After swapping.
a = 10, b = 7

53 COMMENTS

  1. Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point. You clearly know what youre talking about, why waste your intelligence on just posting videos to your blog when you could be giving us something enlightening to read?

  2. I was wondering if you ever considered changing the page layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?

  3. Superb website you have here but I was curious about if you knew of any user discussion forums that cover the same topics talked about in this article? I’d really love to be a part of group where I can get comments from other knowledgeable individuals that share the same interest. If you have any recommendations, please let me know. Bless you!

  4. Undeniably believe that that you stated. Your favourite justification appeared to be at the internet the simplest thing to keep in mind of. I say to you, I definitely get irked whilst other people consider concerns that they plainly do not realize about. You controlled to hit the nail upon the top as smartly as defined out the whole thing with no need side effect , folks can take a signal. Will likely be back to get more. Thank you

  5. Having read this I thought it was very informative. I appreciate you finding the time and effort to put this informative article together. I once again find myself spending a significant amount of time both reading and commenting. But so what, it was still worth it!

  6. 376892 985418Hello, Neat post. There is a difficulty together with your website in internet explorer, could test thisK IE nonetheless is the marketplace leader and a large portion of men and women will leave out your outstanding writing due to this difficulty. 472798

  7. constantly i used to read smaller articles or reviews which also clear their motive, and that is also happening with this piece of writing which I am reading at this place.

  8. 840111 820110Oh my goodness! an outstanding post dude. Thank you Nevertheless Im experiencing problem with ur rss . Do not know why Cannot register for it. Could there be any person acquiring identical rss difficulty? Anybody who knows kindly respond. Thnkx 863401

  9. 562235 490880I enjoyed reading your pleasant web site. I see you offer priceless info. stumbled into this internet site by chance but Im sure glad I clicked on that link. You surely answered all the questions Ive been dying to answer for some time now. Will undoubtedly come back for a lot more of this. 371650

  10. you are actually a just right webmaster. The web site loading velocity is incredible. It sort of feels that you are doing any unique trick. In addition, The contents are masterpiece. you have performed a wonderful process in this topic!

LEAVE A REPLY

Please enter your comment!
Please enter your name here