| | |
min value
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
hello,
why the output below produce number 0, eventhought there is no 0 in the array?
why the output below produce number 0, eventhought there is no 0 in the array?
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> #include <cstdlib> #include <cmath> #include <cstdio> #include <ctime> using namespace std; int i; int x[7]; int A[7], B[7], C[7], D[7], E[7], F[7]; int Min( const int *A, const int Count); int minimum, minA, minB, flagB; int main(void); int count = 7; { 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)); } { cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]); } } printf("\n"); printf ("A\tB\tC\tD\tE\tF"); printf ("\n_\t_\t_\t_\t_\t_\t"); 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]); } cout <<"\n"; // Compare the members int Minimum = A[0]; for (int i=1; i<7; i++) if (minimum > A[i]) Minimum = A[i]; return minimum; } // Announce the result cout << "The minimum value of the array A is "<< A[minA] << "." << endl; } }
Last edited by Ancient Dragon; Nov 6th, 2007 at 9:26 pm. Reason: add code tags
please use code tags or other people won't be able to help you....
here is your code
what compiler do you use? on gcc it doesn't compile....
remove line 2:: #include <conio.h>
also in lines like
to do this type::
here is your code
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio.h> #include <cstdlib> #include <cmath> #include <cstdio> #include <ctime> using namespace std; int i; int x[7]; int A[7], B[7], C[7], D[7], E[7], F[7]; int Min( const int *A, const int Count); int minimum, minA, minB, flagB; int main(void); int count = 7; { 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)); } { cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]); } } printf("\n"); printf ("A\tB\tC\tD\tE\tF"); printf ("\n_\t_\t_\t_\t_\t_\t"); 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]); } cout <<"\n"; // Compare the members int Minimum = A[0]; for (int i=1; i<7; i++) if (minimum > A[i]) Minimum = A[i]; return minimum; } // Announce the result cout << "The minimum value of the array A is "<< A[minA] << "." << endl; } }
what compiler do you use? on gcc it doesn't compile....
remove line 2:: #include <conio.h>
also in lines like
A[i]=(2+pow(x[i],2)); you must cast the operands to double, so that there is no amguity as to which overloaded function of pow the compiler selects..to do this type::
A[i]=( 2+pow( static_cast<double>(x[i]),static_cast<double>(2) ) ); Two roads diverged in a wood, and I— I took the one less traveled by, and that has made all the difference.
by Robert Frost the "The Road Not Taken"
by Robert Frost the "The Road Not Taken"
>>How to use code tags?
Look in the edit box. The instructions are in grey letters. All you have to do is read them.
>>whata is complier?
Too bad I can't issue an infraction for being such a dumbass.
But I hope you were just teasing.
lines 20-25 of your original post: array x is initialized by the program's start-up code to be 0 because the array is in global memory. So 0 ^ <any number here> is always 0.
Look in the edit box. The instructions are in grey letters. All you have to do is read them.
>>whata is complier?
Too bad I can't issue an infraction for being such a dumbass.
But I hope you were just teasing.lines 20-25 of your original post: array x is initialized by the program's start-up code to be 0 because the array is in global memory. So 0 ^ <any number here> is always 0.
Last edited by Ancient Dragon; Nov 6th, 2007 at 9:30 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
i have get the minimum value that I want, but how to get the min from which array?I have done in bold, but its seems like wrong
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <cmath> #include <cstdio> #include <ctime> using namespace std; int i; int x[7]; int A[7], B[7], C[7], D[7], E[7], F[7]; // The members of the array int minimum = numbers[0] ; int minimum, minA, minB, flagB; int main(void) { for(i=1;i<7;i++) { x[i]=i; A[i]=(2+pow(static_cast<double>(x[i]),static_cast<double>(2))); B[i]=(1+pow(static_cast<double>(x[i]),static_cast<double>(3))); C[i]=(2+pow(static_cast<double>(x[i]),static_cast<double>(2)-1)); D[i]=(3*pow(static_cast<double>(x[i]),static_cast<double>(3))); E[i]=(1+pow(static_cast<double>(x[i]),static_cast<double>(2))); F[i]=(3+pow(static_cast<double>(x[i]),static_cast<double>(2))); } { cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] A[%d]=%d\n", i,1, i, A[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] B[%d]=%d\n", i,2, i, B[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] C[%d]=%d\n", i,3, i, C[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] D[%d]=%d\n", i,4, i, D[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] E[%d]=%d\n", i,5, i, E[i]); } cout <<"\n"; for(i=1;i<7; i++) { printf("[%d][%d] F[%d]=%d\n", i,6, i, F[i]); } } printf("\n"); printf ("A\tB\tC\tD\tE\tF"); printf ("\n_\t_\t_\t_\t_\t_\t"); 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]); } cout <<"\n"; // Compare the members int minimum = A[1]; for (i = 1; i < 7; ++i) { if ( A[i] < minimum) { minimum=A[i]; minA = i; return minimum; } cout <<"\n"; // Announce the result cout << "The minimum value of the array A is "<< minimum << "." << endl; minimum = B[1]; for (i = 1; i < 7; ++i) { if (B[i]< minimum) { minimum = B[i]; minB = i; } cout <<"\n"; cout << "The minimum value of the arrays B is "<< minimum << "." << endl; // to determine the minimum whether in A or B minimum = A[minA]; if(B[minB] < minimum) { minimum = B[minB]; flagB = 1; //the minimum is in B if flagB=1 } cout <<"\n"; [B]if(flagB = 1) cout<< "Initial solution in A:" <<minimum << "."<<endl; else cout<< "Initial solution in B:" <<minimum << "."<<endl; return 0;[/B]} } }
Last edited by Ancient Dragon; Nov 6th, 2007 at 10:49 pm. Reason: replace quote tags with code tags
did you compile that? Probably not because it has lots of errors. Start out by counting the open and close braced and make sure they match correctly. Next fix the indention -- its absolutely horrible. Don't be afraid to use the space bar to align the braces and code.
lines 18-23. What is the purpose of X array? Why do you even need it? Did you read what I previously posted about it? Obviously not because you didn't change it.
lines 18-23. What is the purpose of X array? Why do you even need it? Did you read what I previously posted about it? Obviously not because you didn't change it.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
What is the purpose of X array?
the pupose is to get the value.
I have compile bit for the initial solution, why is it 0?
the pupose is to get the value.
•
•
•
•
[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]=3
[2][3] C[2]=4
[3][3] C[3]=5
[4][3] C[4]=6
[5][3] C[5]=7
[6][3] C[6]=8
[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
A B C D E F
_ _ _ _ _ _
3 2 3 3 2 4
6 9 4 24 5 7
11 28 5 81 10 12
18 65 6 192 17 19
27 126 7 375 26 28
38 217 8 648 37 39
The minimum value of the array A is 3.
The minimum value of the arrays B is 2.
Initial solution in B: 0.
Press any key to continue
I have compile bit for the initial solution, why is it 0?
•
•
•
•
What is the purpose of X array?
the pupose is to get the value.
See above.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Yes I see now its initialized on line 19. But still, why do you need that array. You can just simply do this:
Also not that line 6 appears to be wrong -- using * instead of + like the other lines
c++ Syntax (Toggle Plain Text)
for(i=1;i<7;i++) { A[i]=(2+pow(i, 2.0); B[i]=(1+pow(i,3.0); C[i]=(2+pow(i,1.0); D[i]=(3*pow(i,3.0); E[i]=(1+pow(I,2.0); F[i]=(3+pow(I,2.0); }
Also not that line 6 appears to be wrong -- using * instead of + like the other lines
Last edited by Ancient Dragon; Nov 6th, 2007 at 11:57 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- beginners program; can't get min value (C++)
- Win Min error when shutting down windows 98 (Viruses, Spyware and other Nasties)
- how to reset timeout so we will not be disconneceted after 5 min. (Windows 95 / 98 / Me)
Other Threads in the C++ Forum
- Previous Thread: need help error checking my Line editor functions
- Next Thread: The difference of '\n' in windows and linux.
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






