[img]http://img19.imageshack.us/img19/9384/f5.JPG[/img]

#include <stdio.h>
#include <math.h>
void main()
{
double a,b,c,disc,x1,x2;
printf("To find the roots of a quadriatic equation with real roots\n")
disc=b*b-4*a*c
if(disc<0)
printf("The roots are complex",disc);
if(disc>=0)
printf("-b+sqrt(disc)/2a",x1);
printf("-b-sqrt(disc)/2a",x2);


This is what i wrote, i know it is missing alot
but I really dunno how to do it, so can anyone help me to do the rest
so it can run well

Hello,

To start with, when you declare variables, initialize them right away:

double a = b = c = disc = x1 = x2 = 0.0;

Next, you will need to use cin or scanf to read the data into variables.

You will also need to check your operator precidence. Example:

4 * 3 / 4 + 6 = 9

4 * 3 / (4 + 6) = 4 * 3 / 10 = 1.2

Your disc equation will need help.

Let us know how it works.

Christian

double a = b = c = disc = x1 = x2 = 0.0;

It uses equal? i dun get it?

scanf all variables?

Hello,

double a = b = c = disc = x1 = x2 = 0.0;

declares all of those variables as double values, and then assigns them a value of zero.

Remember that in C, = is the assign operator, and == is the equals operator.

scanf(%d, variable); scans in an integer
scanf(%lf, variable); scans in a floating double number

You are going to need to read your C or C++ book to find out how to set these things up properly, and gain a greater understanding of what you are trying to do.

Give it a shot.

Christian

Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(

Hello , this was my homework in the past
i hope it will help you

Attachments
//   
//  12288
//  : 424103019
//Question 2
//Polynomial.cpp
enum Error_code {success,fail};
class Polynomial {
public:
	Polynomial(int = 10);
	Polynomial(const Polynomial &);
	Polynomial operator+(const Polynomial &);
	Polynomial operator-(const Polynomial &);
	Polynomial operator*(const Polynomial &);
	Polynomial &operator=(const Polynomial &);
	Polynomial &operator+=(const Polynomial &);
	Polynomial &operator-=(const Polynomial &);
	Polynomial &set(int=0,double=0);
	void print()const;
	double Get(int =0);
	~Polynomial();
private :
	double *a;
	int grade;
};
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

Polynomial::Polynomial(int s)
{
	grade = (s>0 && s<1000 ? s : 10);
	a = new double[grade+1];
	for(int i=0;i<=grade;i++) 
		a[i] = 0;
		
	
}
Polynomial::Polynomial(const Polynomial &x)
{
	grade = x.grade;
	a = new double [grade+1];
	for(int i=0;i<=grade;i++)
		a[i] = x.a[i];

}
Polynomial &Polynomial::operator =(const Polynomial &x)
{
	if (this != &x)
	{
		if (grade != x.grade) {
			grade = x.grade;
			delete a;
			a = new double [grade+1];
		}
		for(int i=0;i<=grade;i++) 
			a[i] = x.a[i];
		
		
	}
		return *this;
}
			
Polynomial Polynomial::operator +(const Polynomial &x)
{
	int s = grade >= x.grade ? grade : x.grade;
	Polynomial temp(s);
	
	for(int i=0;i<=x.grade;i++)
		temp.a[i] += x.a[i];
	for(int j=0;j<=grade;j++)
		temp.a[j] += a[j];
	return temp;
}
Polynomial Polynomial::operator-(const Polynomial &x)
{
	int i=0,j;
	int s = grade >= x.grade ? grade : x.grade;
	if ((x.grade == grade) && (a[grade]-x.a[x.grade]==0) ) {s--;i = 1;}
	Polynomial temp(s);
	for(j=i;j<=grade;j++)
		temp.a[j-i] += a[j];
	for(j=i;j<=x.grade;j++)
		temp.a[j-i] -= x.a[j];
	return temp;
}
Polynomial &Polynomial::operator +=(const Polynomial &x)
{
	*this = *this +x;
	return *this;
}
Polynomial &Polynomial::operator -=(const Polynomial &x)
{
	*this = *this - x;
	return *this;
}
Polynomial &Polynomial::set(int exp,double coff)
{
	if (exp >=0 && exp<=grade) {
		a[exp] = coff;
		
	}
	return *this;
}
Polynomial Polynomial::operator*(const Polynomial &x)
{
	int s = grade + x.grade,i,j;
	Polynomial temp(s);
	for(i=0;i<=grade;i++)
		for(j=0;j<=x.grade;j++) 
			temp.a[i+j]+=(a[i]*x.a[j]);
	
	return temp;
}

void Polynomial::print()const {
	for(int i=grade;i>=0;i--) 
		cout << (i!= grade && a[i]>=0 ? '+' : ' ' )
		<< a[i] <<  "x^" << i;

	cout << endl;
}
double Polynomial::Get(int exp)
{
	if (exp >= 0 && exp<=grade)
		return a[exp];
		return 0;
}
Polynomial::~Polynomial()
{
	delete []a;
}
int main()
{
	Polynomial A(2),B(5),C;
	
	A.set(2,4).set(1,-5).set(0,6);
	
	B.set(5,1).set(4,4).set(3,3).set(2,-2).set(0,16);
	cout << "A = ";
	A.print();
	cout << "B = ";
	B.print();
	C = A+B;
	cout << "C = A+B : ";
	C.print();
	C = A-B;
	cout << "C = A-B : ";
	C.print();
	C = B-A;
	cout << "C = B-A : ";
	C.print();
	C = B*A;
	cout << "C = A*B : ";
	C.print();
	C += B;
	cout << "C += B : ";
	C.print();
	C -=A;
	cout << "C -= A : ";
	C.print();
	cout << "The coffecient of exp 0 in B is :" << B.Get(0) << endl;
	return 0;
}

Please dont post such huge pics,my connection is slow at the best and it take a long time to download huge pic :-(

sorry about that

Hello , this was my homework in the past
i hope it will help you

urs is too hard for me

This is my project thats due tomorrow
can someone do the rest for me?
i am lack of time now....
coz i got my final tomorrow too

This is my project thats due tomorrow
can someone do the rest for me?
i am lack of time now....
coz i got my final tomorrow too

they dont do others homework here, your going to have to do it, best that you can hope for is a direction to go in, and maybe some hints, but you cant expect someone to just write all the code for you.

This article has been dead for over six months. Start a new discussion instead.