- #include <iostream>
-
#include <conio.h>
-
cpp.
-
-
How to get the random number in matrix like [ ] [ ], the number inside the [ ] [ ], and get the value?
-
-
-
#include <cstdlib>
-
#include <math.h>
-
#include <stdio.h>
-
#include <time.h>
-
using namespace std;
-
-
-
int i;
-
int x[10];
-
int A[10], B[10], C[10], D[10], E[10], F[10];
-
-
int main(void)
-
{
-
{
-
for(i=1;i<7;i++)
-
-
{
-
for(i=1;i<7;i++)
-
{
-
x[i]=i;
-
A[i]=(2+pow(x[i],2));
-
B[i]=(1+pow(x[i],3));
-
C[i]=(2+pow(x[i],2)-1);
-
D[i]=(3*pow(x[i],3));
-
E[i]=(1+pow(x[i],2));
-
F[i]=(3+pow(x[i],2));
-
}
-
{
-
printf("\n");
-
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]);
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]);
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]);
-
}
-
}
-
}
-
}
-
for(i=1;i<7;i++)
-
{
-
cout<<endl;
-
-
printf("%d\t", A[i]);
-
printf("%d\t", B[i]);
-
printf("%d\t", C[i]);
-
printf("%d\t", D[i]);
-
printf("%d\t", E[i]);
-
printf("%d\t", F[i]);
-
}
-
_getch();
-
-
printf("\n");
-
-
printf("Random number: %d\n", rand() % 100);
-
srand ( 1 );
-
-
}
8 2611
Hi,
did I understand you correctly if I assume you want to index a matrix with some values and get the value stored?
Cheers
So you can print rand(), what are you trying to do with that?
If you are attempting to randomly pull values from it, and you have a 2-d array you will need to pull two values from rand both within the limits of your array/matrix. You can call rand(), so I'm assuming saving it isn't the issue, are you having trouble with getting it in the range? If so, you will need to look at the modulus operator ( % ). Otherwise I have no idea what your question is unless it's filling the matrix with random values, in which case you would just implement two for loops to go through each of your index values and save the call to rand() in them.
PS - get rid of getch() and conio.h. They are nonstandard and might break things. Just put a print statement at the bottom of your program, it does the same thing.
dear sicarie,
if i delete conio.h, it will be error, and if i change _getch into printf, undeclaire, so what must I do?
yes. true , did u now how to do?
I have this 2 programming...In the second progrraming I want to call the minimum values from the matrix that I have done, How to the programming? - #include <iostream>
-
#include <conio.h>
-
#include <cstdlib>
-
#include <math.h>
-
#include <stdio.h>
-
#include <time.h>
-
using namespace std;
-
-
void srand ( unsigned int seed );
-
int i, j;
-
int x[10];
-
int A[10], B[10], C[10], D[10], E[10], F[10];
-
-
int main(void)
-
{
-
{
-
for(i=1;i<7;i++)
-
-
{
-
for(i=1;i<7;i++)
-
{
-
x[i]=i;
-
A[i]=(2+pow(x[i],2));
-
B[i]=(1+pow(x[i],3));
-
C[i]=(2+pow(x[i],2)-1);
-
D[i]=(3*pow(x[i],3));
-
E[i]=(1+pow(x[i],2));
-
F[i]=(3+pow(x[i],2));
-
}
-
{
-
printf("\n");
-
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]);
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]);
-
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]);
-
}
-
printf("\n");
-
for(i=1;i<7; i++)
-
-
{
-
printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]);
-
}
-
}
-
}
-
}
-
for(i=1;i<7;i++)
-
{
-
cout<<endl;
-
-
printf("%d\t", A[i]);
-
printf("%d\t", B[i]);
-
printf("%d\t", C[i]);
-
printf("%d\t", D[i]);
-
printf("%d\t", E[i]);
-
printf("%d\t", F[i]);
-
}
-
_getch();
-
-
printf("\n");
-
-
printf("Random number: %d\n", rand() %10);
-
srand ( 1 );
-
-
}
-
#include <iostream>
-
using namespace std;
-
-
int Min(const int *Numbers, const int Count)
-
{
-
int Minimum = Numbers[0];
-
-
for(int i = 0; i < Count; i++)
-
if( Minimum > Numbers[i] )
-
Minimum = Numbers[i];
-
-
return Minimum;
-
}
-
-
double Min(const double *Numbers, const int Count)
-
{
-
double Minimum = Numbers[0];
-
-
for(int i = 0; i < Count; i++)
-
if( Minimum > Numbers[i] )
-
Minimum = Numbers[i];
-
-
return Minimum;
-
}
-
-
int main()
-
{
-
int Nbrs[] = { };
-
int Total = sizeof(Nbrs) / sizeof(int);
-
-
int Minimum = Min(Nbrs, Total);
-
cout << "Minimum: " << Minimum << endl;
-
-
return 0;
-
}
int main()
{ int Nbrs[] = { };
int Total = sizeof(Nbrs) / sizeof(int);
int Minimum = Min(Nbrs, Total);
cout << "Minimum: " << Minimum << endl;
return 0;
}
dunno what ur trying to do here but assuming u wanna find the minimum value in a two dimensional array .. just assign the first element of the first row A[0][0] and iterate thru the matrix and compare each element with this value.. if u find a smaller value then store it in the variable ... something like this: -
int i,j,small=Nbrs[0][0];
-
for(i=0;i<ROWS;i++)
-
for(j=0;j<COLUMNS;j++)
-
if(Nbrs[i][j]<small)
-
small=Nbrs[i][j]
-
this should work
dear sicarie,
if i delete conio.h, it will be error, and if i change _getch into printf, undeclaire, so what must I do?
printf() is a C function, try a cin. You would have to press 'enter', but you could always do a print statement saying "Press enter to continue".
Sorry, I do the mistake, actually I dont want the to make a random number, but i want to choose the minimum values from the matrix that I have done? How to call the number that i done? - >#include
-
>#include
-
>#include
-
>#include
-
>#include
-
>#include
-
>using namespace std;
-
-
-
-
-
> int i, j;
-
> int x[10];
-
> int A[10], B[10], C[10], D[10], E[10], F[10];
-
>
-
> int main(void)
-
>{
-
>{
-
> for(i=1;i<7;i++)
-
>
-
>{
-
> for(i=1;i<7;i++)
-
>{
-
> x[i]=i;
-
> A[i]=(2+pow(x[i],2));
-
> B[i]=(1+pow(x[i],3));
-
> C[i]=(2+pow(x[i],2)-1);
-
> D[i]=(3*pow(x[i],3));
-
> E[i]=(1+pow(x[i],2));
-
> F[i]=(3+pow(x[i],2));
-
>}
-
>{
-
> printf("\n");
-
>
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]);
-
>}
-
> printf("\n");
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]);
-
>}
-
> printf("\n");
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]);
-
>}
-
> printf("\n");
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]);
-
>}
-
> printf("\n");
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]);
-
> }
-
> printf("\n");
-
> for(i=1;i<7; i++)
-
>
-
>{
-
> printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]);
-
>}
-
>}
-
>}
-
>}
-
> for(i=1;i<7;i++)
-
>{
-
> cout<>
-
> printf("%d\t", A[i]);
-
> printf("%d\t", B[i]);
-
> printf("%d\t", C[i]);
-
> printf("%d\t", D[i]);
-
> printf("%d\t", E[i]);
-
> printf("%d\t", F[i]);
-
>}
-
> _getch();
-
>
-
-
-
>}
-
-
-
-
-
>[1][1] A[1]=3
-
>[2][1] A[2]=6
-
>[3][1] A[3]=11
-
>[4][1] A[4]=18
-
>[5][1] A[5]=27
-
>[6][1] A[6]=38
-
>[1][2] B[1]=2
-
>[2][2] B[2]=9
-
>[3][2] B[3]=28
-
>[4][2] B[4]=65
-
>[5][2] B[5]=126
-
>[6][2] B[6]=217
-
>[1][3] C[1]=2
-
>[2][3] C[2]=5
-
>[3][3] C[3]=10
-
>[4][3] C[4]=17
-
>[5][3] C[5]=26
-
>[6][3] C[6]=37
-
>[1][4] D[1]=3
-
>[2][4] D[2]=24
-
>[3][4] D[3]=81
-
>[4][4] D[4]=192
-
>[5][4] D[5]=375
-
>[6][4] D[6]=648
-
>[1][5] E[1]=2
-
>[2][5] E[2]=5
-
>[3][5] E[3]=10
-
>[4][5] E[4]=17
-
>[5][5] E[5]=26
-
>[6][5] E[6]=37
-
>[1][6] F[1]=4
-
>[2][6] F[2]=7
-
>[3][6] F[3]=12
-
>[4][6] F[4]=19
-
>[5][6] F[5]=28
-
>[6][6] F[6]=39
-
-
-
>3 2 2 3 2 4
-
>6 9 5 24 5 7
-
>11 28 10 81 10 12
-
>18 65 17 192 17 19
-
>27 126 26 375 26 28
-
>38 217 37 648 37 39
-
>
-
>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: August1 |
last post by:
A handful of articles have been posted requesting information on how
to use these functions in addition to the time() function as the seed
to generate unique groups (sets) of numbers - each group...
|
by: Dennis |
last post by:
I would like to dynamically allocate in a sub a 2 dimensional Array
float *myarray = new float ;
of course I get an error. How do you allocate a 2D array using the New
operator?
I...
|
by: Josh |
last post by:
Howdy
i was recently given a program to do. I have to create a 2d matrix
with pointers i have the whole idea down with pointers but there is a
problem with one of them i have the code written down...
|
by: jimmy |
last post by:
Hi,
Have tried my best but can't seem to get it.
I have a Matrix and a Vector class that I would like to be in a
Geometry namespace. More detail...
****** Matrix.h ******
#include...
|
by: Chris Gordon-Smith |
last post by:
I have a simulation program that calls the rand() function at various points
while it executes.
For the user interface that displays statistics etc. while the program runs,
I use the Lazarus GUI...
|
by: Skay |
last post by:
Someone challenged me to create a dynamic multidimensional array using
auto_ptr
http://www.gotw.ca/gotw/042.htm
Provides a good way to create a single dimensional array using an adapter.
...
|
by: Cuthbert |
last post by:
After compiling the source code with gcc v.4.1.1, I got a warning
message:
"/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the
'gets' function is dangerous and should not be...
|
by: ds |
last post by:
Hi all,
rand() is not thread safe, a fact that may not be so bad after all..
However, I face the following problem: a piece of code uses rand() to
get a random sequence, but always seeds with...
|
by: lancered |
last post by:
Hi dear all,
I am using Python2.4.2+NumPy1.0.1 to deal with a parameter
estimation problem with the least square methods. During the
calculations, I use NumPy package to deal with matrix...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
| |