Lastest Code
Submit Code
Help/Feedback
Untitled 98ec3
Submitted by:
Anonymous
at
2010-07-18 10:42:34
Tags:
Ads
View Plain Text
Share
#include <iostream> #include <string.h> using namespace std; int coef[9]; void generate(int ind) { if(ind >= 0) { if(coef[ind] == -1) { cout<<"-x^"; } else if(coef[ind] == 1) { cout <<"x^"; } else { cout <<coef[ind]<<"x^"; } if(ind > 0) cout<<ind; else cout<<endl; for(int i = ind-1;i>=0;i--) { if(coef[i] != 0) { if(coef[i] == 1) cout << " + x^"; else if(coef[i] == -1) cout << " - x^"; else if(coef[i] > 0) cout <<" + "<<coef[i]<<"x^"; else cout <<" - "<<coef[i]<<"x^"; if(i>0) cout<<i; else cout<<endl; } } } } int main() { int num; int ind = -1; while(cin >> num) { coef[8] = num; if(coef[8] != 0) ind = 8; for(int i = 7;i>=0;i--) { cin >> coef[i]; if(ind < 0 && coef[i] != 0) ind = i; } generate(ind); } }
©2010 by
takien.com