Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 16th, 2007, 08:46 AM
Authorized User
 
Join Date: May 2007
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
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
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
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.