| | |
need help for programming
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 2
Reputation:
Solved Threads: 0
hello, i need the help for computer programming in the class.
the question is below. i try to write the program, but it comes out a lot of error. please, help me to do this problem.
Write a C++ program for the function
f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3
Create an array with elements:
-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3
Compute the value of f1(x) for each element of the array.
Display results in a table:
element value f1(x)
--- --------------------------------------
0 -4.3
therefore, i start the program like
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
void msort(float y[],int);
int main()
{
const int size=8;
float arry[size]={-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3},i;
cout<<"element: "<<size<<"value: "<<value<<"fl(x): "<<msort<<endl;
cout<<"----------------------------------------\n";
for (int i=0;i<10;i++)
cout<<setw(3)<<i ;
array(ary,size);
for(int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
msort(arry,num);
for (int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
cout<<endl;
return 0;
}
void msort(float list[],int x)
{
int i;
float x;
for (int i=0;i<size;i++)
{
f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3
}
return
}
the question is below. i try to write the program, but it comes out a lot of error. please, help me to do this problem.
Write a C++ program for the function
f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3
Create an array with elements:
-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3
Compute the value of f1(x) for each element of the array.
Display results in a table:
element value f1(x)
--- --------------------------------------
0 -4.3
therefore, i start the program like
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
void msort(float y[],int);
int main()
{
const int size=8;
float arry[size]={-4.3, 1.9, 2.5, -6.1, -9.5, 8.6, 7.2 , -11.3},i;
cout<<"element: "<<size<<"value: "<<value<<"fl(x): "<<msort<<endl;
cout<<"----------------------------------------\n";
for (int i=0;i<10;i++)
cout<<setw(3)<<i ;
array(ary,size);
for(int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
msort(arry,num);
for (int i=0;i<size;i++)
cout<<setw(3)<<arry[i];
cout<<endl;
return 0;
}
void msort(float list[],int x)
{
int i;
float x;
for (int i=0;i<size;i++)
{
f1(x) = 2.6*x^3 - 5.7*x^2 + 4.9x - 15.3
}
return
}
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
Please use code tags.
^ in C++ is not number to the whatever power it is the bitwise OR. What you could do is write your own pow function eg.
As for your code if you want size to be global declare it outside of main, or you could pass it to msort as a const parameter. The rest I not going to bother reading cause its a pain without code tags
^ in C++ is not number to the whatever power it is the bitwise OR. What you could do is write your own pow function eg.
C++ Syntax (Toggle Plain Text)
float myPow(float value,int power) { int i = 0; float tempValue = value; for(i = 1; i < power; i++) { value = value * tempValue; } return value; }
![]() |
Similar Threads
- Good books on Shell Programming/Perl (Perl)
- Shell Programming (Shell Scripting)
- Programming (C++)
- Professional web design and programming services (Post your Resume)
- Where to get started with Web Programming (IT Professionals' Lounge)
- Programming in Linux? (*nix Software)
- Efficient Programming (Computer Science)
- New To Programming = ME!! (C++)
Other Threads in the C++ Forum
- Previous Thread: Printing a Hash Table
- Next Thread: Help with simple problem
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete deploy desktop directshow dll download dynamic 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 node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





