Saturday, 2 June 2012

C++ Program to Calculate Polynoms

C++ Program to  Calculate Polynoms

#include <iostream.h>
#include <math.h>
//Defining variables
int result=0; //here will be stored the result
int *arr; //here will be stored the numbers
int power; //this is the maximum power
int x; //the value for "x"

//Beginning the main function
void main()
 cout << "What s the maximum power in the polynom? : ";
 cin >> power;
 cout << endl;

 arr=new int[power]; //creates an array with "power" cells
 //Asking the user to enter the values...
 for(int n=0;n<power+1;n++)
  cout <<"A"<<power-n<<" = ";
  cin >> arr[power-n];

 cout << "The polynom is: ";

 //Prints the polynom on the screen
 for(int go=power; go >-1; go--)
  if(go > 0)
   cout <<arr[go]<<"*x^"<<go<<" + ";
   cout <<arr[go]<<"*x^"<<go;
 cout <<endl;
 cout <<"Enter value for X : ";
 cin >> x;

 //Calculating the polynom
 for(int cal=0; cal < power+1; cal++)

 cout <<" Y(x)= "<< result<<endl; // showing the result


Post a Comment


Twitter Delicious Facebook Digg Stumbleupon Favorites More