All about problems in Volume III. If there is a thread about your problem, please use it. If not, create one with its number in the subject.
Moderator: Board moderators
by crystaltanvir » Mon Oct 18, 2010 8:40 pm
I'm getting presentation error for this problem... I can't find where's the problem... Somebody please help me...- Code: Select all
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
int p[9];
while(cin >> p[8] >> p[7] >> p[6] >> p[5] >> p[4] >> p[3] >> p[2] >> p[1] >> p[0])
{
int c = 0;
if(p[8] != 0)
{
if(p[8] == 1) cout << "x^8" ;
else if(p[8] == -1) cout << "-x^8" ;
else if(p[8] > 0) cout << p[8] << "x^8" ;
else cout << " -" << fabs(p[8]) << "x^8" ;
c++;
}
if(p[7] != 0)
{
if(c != 0)
{
if(p[7] == 1) cout << " + x^7" ;
else if(p[7] == -1) cout << " - x^7" ;
else if(p[7] > 0) cout << " + " << p[7] << "x^7" ;
else cout << " - " << fabs(p[7]) << "x^7" ;
}
else
{
if(p[7] == 1) cout << "x^7" ;
else if(p[7] == -1) cout << "-x^7" ;
else if(p[7] > 0) cout << p[7] << "x^7" ;
else cout << "-" << fabs(p[7]) << "x^7" ;
}
c++;
}
if(p[6] != 0)
{
if(c != 0)
{
if(p[6] == 1) cout << " + x^6" ;
else if(p[6] == -1) cout << " - x^6" ;
else if(p[6] > 0) cout << " + " << p[6] << "x^6" ;
else cout << " - " << fabs(p[6]) << "x^6" ;
}
else
{
if(p[6] == 1) cout << "x^6" ;
else if(p[6] == -1) cout << "-x^6" ;
else if(p[6] > 0) cout << p[6] << "x^6" ;
else cout << "-" << fabs(p[6]) << "x^6" ;
}
c++;
}
if(p[5] != 0)
{
if(c != 0)
{
if(p[5] == 1) cout << " + x^5" ;
else if(p[5] == -1) cout << " - x^5" ;
else if(p[5] > 0) cout << " + " << p[5] << "x^5" ;
else cout << " - " << fabs(p[5]) << "x^5" ;
}
else
{
if(p[5] == 1) cout << "x^5" ;
else if(p[5] == -1) cout << "-x^5" ;
else if(p[5] > 0) cout << p[5] << "x^5" ;
else cout << "-" << fabs(p[5]) << "x^5" ;
}
c++;
}
if(p[4] != 0)
{
if(c != 0)
{
if(p[4] == 1) cout << " + x^4" ;
else if(p[4] == -1) cout << " - x^4" ;
else if(p[4] > 0) cout << " + " << p[4] << "x^4" ;
else cout << " - " << fabs(p[4]) << "x^4" ;
}
else
{
if(p[4] == 1) cout << "x^4" ;
else if(p[4] == -1) cout << "-x^4" ;
else if(p[4] > 0) cout << p[4] << "x^4" ;
else cout << "-" << fabs(p[4]) << "x^4" ;
}
c++;
}
if(p[3] != 0)
{
if(c != 0)
{
if(p[3] == 1) cout << " + x^3" ;
else if(p[3] == -1) cout << " - x^3" ;
else if(p[3] > 0) cout << " + " << p[3] << "x^3" ;
else cout << " - " << fabs(p[3]) << "x^3" ;
}
else
{
if(p[3] == 1) cout << "x^3" ;
else if(p[3] == -1) cout << "-x^3" ;
else if(p[3] > 0) cout << p[3] << "x^3" ;
else cout << "-" << fabs(p[3]) << "x^3" ;
}
c++;
}
if(p[2] != 0)
{
if(c != 0)
{
if(p[2] == 1) cout << " + x^2" ;
else if(p[2] == -1) cout << " - x^2" ;
else if(p[2] > 0) cout << " + " << p[2] << "x^2" ;
else cout << " - " << fabs(p[2]) << "x^2" ;
}
else
{
if(p[2] == 1) cout << "x^2" ;
else if(p[2] == -1) cout << "-x^2" ;
else if(p[2] > 0) cout << p[2] << "x^2" ;
else cout << "-" << fabs(p[2]) << "x^2" ;
}
c++;
}
if(p[1] != 0)
{
if(c != 0)
{
if(p[1] == 1) cout << " + x" ;
else if(p[1] == -1) cout << " - x" ;
else if(p[1] > 0) cout << " + " << p[1] << "x" ;
else cout << " - " << fabs(p[1]) << "x" ;
}
else
{
if(p[1] == 1) cout << "x" ;
else if(p[1] == -1) cout << "-x" ;
else if(p[1] > 0) cout << p[1] << "x" ;
else cout << "-" << fabs(p[1]) << "x" ;
}
c++;
}
if(p[0] != 0)
{
if(c != 0)
{
if(p[0] == 1) cout << " + 1" ;
else if(p[0] == -1) cout << " - 1" ;
else if(p[0] > 0) cout << " + " << p[0] ;
else cout << " - " << fabs(p[0]) ;
}
else
{
if(p[0] == 1) cout << "1" ;
else if(p[0] == -1) cout << "-1" ;
else if(p[0] > 0) cout << p[0] ;
else cout << "-" << fabs(p[0]) ;
}
c++;
}
if(c == 0) cout << 0;
cout << endl;
}
}
TANVIR
-
crystaltanvir
- New poster
-
- Posts: 6
- Joined: Mon Oct 18, 2010 8:13 pm
- Location: Bangladesh
by sohel » Tue Oct 19, 2010 6:04 am
- Code: Select all
if(p[8] != 0)
{
if(p[8] == 1) cout << "x^8" ;
else if(p[8] == -1) cout << "-x^8" ;
else if(p[8] > 0) cout << p[8] << "x^8" ;
else cout << " -" << fabs(p[8]) << "x^8" ;
c++;
}
last else -
cout << " -"shouldn't it be
cout << "-"And don't create a new thread for a problem whose discussions already exist. Make your post in an existing thread of 392.
-

sohel
- Guru
-
- Posts: 865
- Joined: Thu Jan 30, 2003 5:50 am
- Location: University of Texas at San Antonio
-
by crystaltanvir » Sun Oct 31, 2010 1:29 am
Thanx bro... It was a silly mistake... Its accepted now... Very vey thanx...
TANVIR
-
crystaltanvir
- New poster
-
- Posts: 6
- Joined: Mon Oct 18, 2010 8:13 pm
- Location: Bangladesh
Return to Volume III
Who is online
Users browsing this forum: No registered users and 0 guests