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 June 6th, 2006, 09:28 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Outputting Array

Hi,
I really new on C++, and I try to output an array (All possible output)
for example:
we have an array with 3 element, all possible answer would be 3! = 3 * 2 * 1 = 6

/--------------------------------------------------------/
#include <iostream>
using namespace std;

int main()
{
  int arr[3] = { 1, 2, 3 };

  for (int i=0; i<3; i++)
  {
    for (int j=0; j<3; j++)
    {
      if (i != j)
      {
    for (int k=0; k<3; k++)
    {
      if ((k != i) && (k != j))
      {
        cout << arr[i] << "\t" << arr[j] << "\t" << arr[k] << "\n";
      }
      }
    }
   }
  } // END For

  return 0;
}

/------------------------------------------------------/

On example above I use 3 FOR loop and 2 IF. My question is if we have an array with 200 element, we will have 200 FOR loop and 199 IF.
Is there a better way to use (less using FOR and IF)? if yes how?

(As everyone in this forum know being C++ programmer means we have to solve problems by ourselves, but it's been 1 month I try to figure this out but I cannot, and I hope you guys can help me for that)


Thanks
Regards

Reply With Quote
  #2 (permalink)  
Old June 13th, 2006, 10:52 PM
Registered User
 
Join Date: Jun 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No buddy, ya don have to.
Lisn up, for extremely huge datas like the 200 variable array, u're talking 'bout, the latest industry standard is to use database management programs like oracle etc. Later on, you can integrate this data with your C++ program. Some programmers even use MS Access. Alternately the problem can be solved by Object Oriented Programming or OOP approach. But since you are new to C++, I'll leave it for your book to explain.

Reply With Quote
  #3 (permalink)  
Old June 14th, 2006, 08:24 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank You

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not outputting a specific node zach_1988 XSLT 3 December 2nd, 2008 10:49 AM
outputting to multiple documents? wilgartw XSLT 3 November 7th, 2007 07:52 PM
Outputting Conditional Comments ole_v2 XSLT 2 November 13th, 2006 03:39 PM
Outputting table permissions crisan Access 1 May 25th, 2005 06:39 AM





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