473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Convert one function procesr(n,C) in matrice[i][j] ant print it in the screen

Hi,I made a program which gives all possible combinations in the screen of DEVC++.

So I want to print the same result in the screen, but in this case like one matrice[i][j], because then my program have continue with matrice, not with function. Many Thanks!

The function : procesar give me the next result in the screen:
Expand|Select|Wrap|Line Numbers
  1. 123
  2.  213
  3.  231
  4.  321
  5.  312
  6.  132
All these dates ( rows&cols) I want to present with one matrice[6][3]
cout<<" The converted matrice is :"<<matriz[i][j];

Because the previos results it appear like one function:procesar(n,C)
The code of the combination function is :
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <conio.h> 
  3. using namespace std;
  4.  
  5. int procesar(int n, int C[])
  6.  {
  7.      int i;
  8.      int inc = 0;
  9.      int it = n * (n - 1);
  10.  
  11.      while (inc < it) 
  12.      {
  13.          for (i = n - 1; i > 0; i--) 
  14.          {
  15.              int aux = C[i-1];
  16.              C[i-1] = C[i];
  17.              C[i] = aux;
  18.              for (int j = 0; j < n; j++)
  19.  
  20.                  cout <<" "<< C[j];
  21.              cout << endl;
  22.              inc++;
  23.            }}}
  24. int main()
  25.  {
  26.      int n;
  27.  
  28.      cout << "How many numbers of digits you want to use for a combination: ";
  29.      cin >> n;
  30.  
  31.      int C[n];
  32.  
  33.      for (int i = 0; i < n; i++) 
  34.      {
  35.          cout << "Input digit: " << i + 1 << ": ";
  36.          cin >> C[i];
  37.      }
  38.  
  39.      procesar(n, C);
  40.  
  41.  
  42.  getch();
  43.  
  44.  
  45.      return 0;
  46.  }
Aug 2 '12 #1
5 1437
weaknessforcats
9,208 Expert Mod 8TB
You need a function like this one you wrote

Expand|Select|Wrap|Line Numbers
  1. int procesar(int n, int C[])
  2. { etc...
  3.  
but takes a matrice argument.There are a number of ways to do this (read http://bytes.com/topic/c/insights/77...rrays-revealed ).

The easiest way is to have an argument for the first dimension, the second dimension and the address of element
[0][0]. Since the matrice contains int, the argument would be an int*:

Expand|Select|Wrap|Line Numbers
  1. int procesar(int i, int j, int* c)
  2. { etc...
  3.  
In this function you have an outer loop than goes from 0 to i and inside this loop is a secnd loop that goes from 0 to j.

Unside this second loop you can print c[i][j] but you have to calculate it since c is only an int* making c a one dimensional array.

The calculation is that i (a row) has j elements. So i*j gives the row where j is the col. c[i*j + j] is the element. This si what you print inside the secnd loop.

When you exit the inner loop you can print the \n in the outer loop before going back to the top of the outer loop.
Aug 2 '12 #2
Thankīs a lot weaknessforcats ,I will try to make solution with your advise.I will reply you soon,letīs see what I can make about this problem,thankīs onceagain.....
Aug 6 '12 #3
Thankīs a lot weaknessforcats ,I will try to make solution with your advise.I will reply you soon,letīs see what I can make about this problem,thankīs onceagain.....
By the whay, I am making another works,thatīs why I reply to you not right now,ok.
Aug 6 '12 #4
Excuseme weaknessforcats , can you show me the code for my case in dettails,because I didnīt understood it.
Aug 6 '12 #5
weaknessforcats
9,208 Expert Mod 8TB
Did you read the article?

The solution you want is there.
Aug 6 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: YERVANT | last post by:
I would like use the Print Screen Button to copy a part of page using ASP. En fact, I use a data access page of a chart (pivot) created by access. And I would like copy only the chart. I think...
0
by: Vicente Nicolau | last post by:
Hello, I'm programming an application and I need to disable the print screen key. How can I do it? Can I use the UIPermissions to disable the print screen key? Thanks
2
by: Tim Marsden | last post by:
Is there a way of turning off or preventing the print screen function while my application is running. (VB.NET). Thanks Tim
3
by: Zlatko Matiæ | last post by:
Hello. I tried to print the current situation on the form/subform/subform...but it seems that Access prints all the records on all the subforms. I would like to print just the image (something...
0
by: melanieab | last post by:
Hi, I have a tabpage with a print button. This button tries to do a print screen, and it works fine the first time, but if I try to press print again, I get error: An unhandled exception of type...
2
by: chicken butt | last post by:
I have a back office app developed using the 1.1 framework with VB.NET. When we print using the browser, the end result is garbled pretty good. I am wondering if it is possible to create a...
2
by: toronto | last post by:
Seasons Greetings Everyone! I want to use JavaScript's event object to detect whether someone has pressed the 'PrintScreen' key to screenshot, via the Windows Clipboard, and to print website...
8
by: =?Utf-8?B?THVpZ2k=?= | last post by:
Hi all, anyone knows if is it possible to insert (and obviously save) a Windows print screen in a GridView cell? (ASP.NET 2.0). Thanks in advance. -- Luigi
3
by: Joe Duchtel | last post by:
Hello - I would like to create an application that starts up upon login (e.g. Startup folder) and then waits for the Alt+Print Screen button to be pushed. I still want this button to put a...
4
by: =?Utf-8?B?bjg=?= | last post by:
This may be the stupidest question ever, but how does the "print screen" work on Vista? I've tried every possible thing with Shift, Ctrl, Alt..... Still seeking the resolution.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.