Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2007, 08:46 AM
Authorized User
Points: 395, Level: 6
Points: 395, Level: 6 Points: 395, Level: 6 Points: 395, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: London, , United Kingdom.
Posts: 73
Thanks: 4
Thanked 0 Times in 0 Posts
Default Some problems




If have two variables a=4 b=6 want to swap their values without using the third variable. How can I do this in C?


I want to make a pyramid of any shape (3D array) using loops?



Any answers with code will be really appreciated.




Cheers
Sheraz
__________________
Cheers
Sheraz
Reply With Quote
  #2 (permalink)  
Old November 16th, 2007, 01:59 PM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Swapin, enjoy..

Code:
//Swaping, add using for cout,endl..
int main(void)
{
 int a=321,b=258;
 cout << "Before swaping: a=" << a << " b=" << b << endl;
 a=a+b; 
 b=a-b; 
 a=a-b; 
 cout << "After Swaping: a=" << a << " b=" << b << endl;
 return 0;
}
Reply With Quote
  #3 (permalink)  
Old November 18th, 2007, 07:10 AM
Registered User
 
Join Date: Nov 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gulina
Default

what a smart way:)

Reply With Quote
  #4 (permalink)  
Old April 11th, 2008, 03:42 PM
Registered User
 
Join Date: Apr 2008
Location: Coimbatore, Tamil Nadu, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

int main()
{
 int a=321,b=258;
 cout << "Before swaping: a=" << a << " b=" << b << endl;
//Using bitwise ex-or operation
 b^a^b^a;
 cout << "After Swaping: a=" << a << " b=" << b << endl;
 return 0;
}

Vikki
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems already! KennySargent BOOK: Professional XNA Programming 2nd Edition ISBN: 978-0-470-26128-6 4 April 7th, 2008 03:36 AM
Have 2 problems so far... Soulcatcher BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 June 20th, 2007 12:57 PM
c problems saurabh1983in C++ Programming 6 November 29th, 2005 04:23 AM
validate.asp problems and logon.asp problems p2ptolu Classic ASP Databases 0 February 16th, 2005 02:34 PM
Problems kilika Javascript 1 October 3rd, 2003 02:42 AM



All times are GMT -4. The time now is 12:53 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.