pjjuang24

February 21st, 2008, 06:39 AM

Hi I am very new to programming in general and this semester I have to take a C programming class in which I have never seen computer language in my life so I have some questions about my homework if anyone could help me.

So the first one this is what i have so far...but it will not compile I do not know what is wrong with it

//This program that takes three values a, b, and c to

//identify if a triangle can be formed that have the given lengths. It //also tells you if it is equilateral or not, isosceles or not, and/or right //angled or not

#include <stdio.h>

main()

{

double a, b, c;

printf("Enter three values>");

scanf("%lf, %lf, %lf", &a, &b, &c);

if ((a>1) (b>1) (c>1))

{

if ((a+b>c) && (b+c>a) && (c+a>b))

{

printf("A triangle can be formed with these lengths\n");

}

if ((a==b) && (b==c) && (a==c))

{

printf("This is an equilateral triangle\n");

}

else

{

printf("This is not an equilateral triangle\n");

}

if((a==b) || (b==c) || (c==a))

{

printf("This is an isosceles triangle\n");

}

else

{

printf("This is not an isosceles triangle\n");

}

if ((pow(c,2)==pow(a,2)+pow(b,2)) || (pow(a,2)==pow(b,2)+pow(c,2)) || (pow(b,2)==pow(a,2)+pow(c,2)))

{

printf("This is a right triangle\n");

}

else

{

printf("This is not a right triangle\n");

}

else

{

printf("A triangle cannot be formed with these lengths\n");

}

}

else

{

printf("These numbers cannot form a triangle\n");

}

}

The second question is...after I compile the program, then I tried to input negative numbers but the output said command cannot be found. Is there an "if" function I can put in the program that will also read the negative numbers? or what do I do?

//This program will tell you if three points on a coordinate graph are

//collinear.

#include <stdio.h>

main()

{

double x1, y1, x2, y2, x3, y3;

printf("Enter three points>");

scanf("%lf, %lf, %lf, %lf, %lf, %lf", &x1, &y1, &x2, &y2, &x3, &y3);

if (((x1==x2) && (x2==x3) && (x1==x3)) || ((y1=y2) && (y2=y3) &&(y1==y3)))

printf("These points are collinear\n");

else

printf("These points are not collinear\n");

}

If you could help that would be great thank you so much!!

Polly

So the first one this is what i have so far...but it will not compile I do not know what is wrong with it

//This program that takes three values a, b, and c to

//identify if a triangle can be formed that have the given lengths. It //also tells you if it is equilateral or not, isosceles or not, and/or right //angled or not

#include <stdio.h>

main()

{

double a, b, c;

printf("Enter three values>");

scanf("%lf, %lf, %lf", &a, &b, &c);

if ((a>1) (b>1) (c>1))

{

if ((a+b>c) && (b+c>a) && (c+a>b))

{

printf("A triangle can be formed with these lengths\n");

}

if ((a==b) && (b==c) && (a==c))

{

printf("This is an equilateral triangle\n");

}

else

{

printf("This is not an equilateral triangle\n");

}

if((a==b) || (b==c) || (c==a))

{

printf("This is an isosceles triangle\n");

}

else

{

printf("This is not an isosceles triangle\n");

}

if ((pow(c,2)==pow(a,2)+pow(b,2)) || (pow(a,2)==pow(b,2)+pow(c,2)) || (pow(b,2)==pow(a,2)+pow(c,2)))

{

printf("This is a right triangle\n");

}

else

{

printf("This is not a right triangle\n");

}

else

{

printf("A triangle cannot be formed with these lengths\n");

}

}

else

{

printf("These numbers cannot form a triangle\n");

}

}

The second question is...after I compile the program, then I tried to input negative numbers but the output said command cannot be found. Is there an "if" function I can put in the program that will also read the negative numbers? or what do I do?

//This program will tell you if three points on a coordinate graph are

//collinear.

#include <stdio.h>

main()

{

double x1, y1, x2, y2, x3, y3;

printf("Enter three points>");

scanf("%lf, %lf, %lf, %lf, %lf, %lf", &x1, &y1, &x2, &y2, &x3, &y3);

if (((x1==x2) && (x2==x3) && (x1==x3)) || ((y1=y2) && (y2=y3) &&(y1==y3)))

printf("These points are collinear\n");

else

printf("These points are not collinear\n");

}

If you could help that would be great thank you so much!!

Polly