C/C++ :: Calculating Hypotenuse Of A Triangle
Apr 3, 2014
I wrote a function to calculate the hypotenuse of a triangle. My code looks fine but when i enter the two sides it does not give out the right answer. I really don't know what to do.
#include <stdio.h>
#include<Windows.h>
#include<math.h>
double hypotenuse(double side1, double side2);
int main(void){
double side1, side2, hyp;
[Code] .....
View 8 Replies
ADVERTISEMENT
May 12, 2014
How to do the function part here is the question. "Write a program that calculates the hypotenuse of a right triangle. the program should ask the users to enter the length of the two legs of the right triangle and the program should call a function hypotenuse() that will calculate and display the length of of the hypotenuse. NOTE: The program should include a prototype for the function hypotenuse()" i have this so far
#include <iostream>
4 #include <cmath> // Needed to use the sqrt function
5 using namespace std;
6
7 int main()
8 {
9 double a, b, c;
[Code] ....
View 4 Replies
View Related
Mar 9, 2013
error C2660: 'CalculateHypotenuse' : function does not take 0 arguments
Code:
#include"header.h"
#include<stdio.h>
#include<conio.h>
#include<math.h>
[Code] .....
View 6 Replies
View Related
Nov 7, 2014
I need to calculate the area of a triangle using heron's formula. I wrote the code below and i need to modify it so that a user is required to keep entering the three side until he/she decides to stop. If the three sides entered make an invalid triangle, the user is required to re-enter the values until valid triangle is formed. Then the area is displayed.
#include <iostream>
#include <cmath>
using namespace std;
int main(){
double a,b,c=0;
double s,A=0;
[Code] .....
the screen output should like this:
Enter three sides of a triangle: 0 1 2 Error!
Re-enter three sides of a triangle: -1 1 2 Error!
Re-enter three sides of a triangle: 3 4 5 => 6
Continue (y/n)? y
Enter three sides of a triangle: 1 1 2 Error!
Re-enter three sides of a triangle: 6 8 10 => 24
Continue (y/n)? n
Done!
Please note that Continue (y/n)? only displayed after a valid triangle is formed. Otherwise, the user needs to re-enter sides until it's valid.
View 1 Replies
View Related
Dec 7, 2014
On a right angled triangle, if the user inputs only ONE side length (not the hypotenuse) and only ONE angle, what code is required to work out the hypotenuse? I know how to work out the final side and the remaining angle once I have this.
View 4 Replies
View Related
Oct 2, 2014
So this is a programming assignment right now that I'm working on. I was able to satisfy two or the requirements: to print all Pythagorean triples with the length of the hypotenuse being below the entered value and to state how many Pythagorean triples there are. I've come into a problem, though, since the final requirement is to state the largest Pythagorean triple. The problem is that it posts the values of a,b,c after the loop exits, which are going to be the values right below N (eg. N=19, then a,b,c=16,17,18).
Here is the program:
Code:
#include <stdio.h>
void main () {
int a,b,c,N;
int ctr = 0;
[Code] ....
My questions is how to fix this problem because putting it in the for loop will just cause it to repeat all values.
View 4 Replies
View Related
Oct 7, 2013
What the heck is wrong with my logic? I just print a rectangle!!! I have played with thing for ever it seems. I thought the rotating part would be hard but now I find myself stuck.
Code:
#include <istream>
#include "triangle.h"
using namespace std;
void triangle::create_triangle() {
[Code] ....
View 13 Replies
View Related
Jan 12, 2015
I originally had the user input three different lengths and then used this to determine whether or not it was a right triangle.
if(c==sqrt(a*a+b*b)||a==sqrt(b*b+c*c)||b=sqrt(a*a+b*b))
Now it has to be modified in order to accept the input 2,2 4,4 and 6,8(only an example) and be able to find out if it is a right triangle. I was told that arrays were not necessarily the only way to go about it.
View 1 Replies
View Related
Mar 2, 2015
I need to find out neighbors of a triangle and loop it over entire unstructured grid. How to do it?. Cell numbers are random so I am unable to loop over all cells.
View 9 Replies
View Related
Jun 26, 2013
I intended to compute perimeter of a triangle. The problem is the initial value for the triangle.
#include <iostream>
#include <cmath>
using namespace std;
struct Point{
double x;
double y;
[Code] ......
I expect to get 0 for triangle1, but I get some strange value...
Here is the result
Type x for point1 : 1
Type y for point1 : 1
Type x for point2 : 3
Type y for point2 : 1
Type x for point3 : 1
Type y for point3 : 3
The perimeter of the triangle1 is : 2.82843
The perimeter of the triangle2 is : 6.82843
View 2 Replies
View Related
Jan 3, 2014
After trying to understand the problem i finally gave up. The problem requires me to calculate the sum of the biggest numbers in a triangle.
For example: 5
4 0
3 8 2
2 7 9 6
Here is the solved problem from the book(It uses recursion, but i do not get it at all)
#include <iostream>
#include <fstream>
using namespace std;
int triunghi[50][50], n, sum=0;
int suma_max(int i, int j);
[Code] .....
I doesn't give me the same result(26) if a change the order of the numbers in the triangle.
View 3 Replies
View Related
Jun 21, 2013
Similar to Pascal’s triangle, the difference triangle has some interesting properties that find applications in various fields of the natural and applied sciences. In simple terms, a difference triangle is a set of integers arranged in an inverted triangle where each inverted triangle triad has its lower element equal to the difference (absolute value) of the two elements in the upper row. A difference triangle can be created from a sequence of integers forming the uppermost row by iteratively taking differences between consecutive terms to form the next row until a single-element row is created.
Example Consider the sequence 5, 8, 13, 21, 34, 55 from the Fibonacci series as the uppermost row of the difference triangle. The difference between successive elements form a new set: 3 (= 8 – 5), 5 (= 13 – 8), 8 (= 21 – 13), 13 (= 34 – 21), and 21 (= 55 – 34). The process can then be repeated until there is only one element left giving the following difference triangle:
5 8 13 21 34 55
3 5 8 13 21
2 3 5 8
1 2 3
1 1
0
Problem Write a program that forms a difference triangle using a given series of numbers as topmost row.
View 2 Replies
View Related
Dec 27, 2013
Write a class called MyTriangle, which models a triangle with 3 vertices, is designed as follows. It contains:
1. The MyTriangle class uses three MyPoint instances as the three vertices.
2. Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.
3. A constructor that constructs a MyTriangle with three points v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).
4. An overloaded constructor that constructs MyTriangle given three instances of MyPoint.
5. A toString() function that returns a string description of the instance in the format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".
6. A getPerimeter() function that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.
7. Also write a test program (called main.cpp) to test all the functions defined in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).
class MyTriangle {
MyPoint v1;
MyPoint v2;
MyPoint v3;
public:
MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3) {
[Code] .....
View 3 Replies
View Related
Nov 16, 2014
I was asked to build a small program to calculate the are of a Triangle but my code must have some problem.. />
#include "stdafx.h"
void main()
{
int a,b;
[Code]....
I get this errors:
-warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
-warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
View 4 Replies
View Related
May 13, 2014
So, I have created a class called "point" and i have 4 "point" objects. They only have 2 variables, x and y (their position). The first 3 points form a triangle and now I need to tell if the forth one is inside or outside. I have found some solutions but they involve heavy math (they are based on the sum of the angles or something like that). I want to know if there is any way to solve this only by using the distance between points. I have created a function which takes 2 "point" objects and returns a float value which is their distance.
Here is some code:
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;
[Code]....
View 5 Replies
View Related
Nov 29, 2013
Finally got a programme partially working, why the values are not showing? Is this down to incorrect formula or i havent declared the values etc?
Code:
#include <stdio.h>
#include <math.h>
float timeconstant(float R, float C);
float R;
float C;
float time_c;
[Code] ....
View 2 Replies
View Related
Jan 1, 2015
I'm making a program that prints a triangle of @ signs given rows (but not columns).
For example, the output with rows = 4 would be:
@@@@
@@@
@@
@
and rows = 3 would be:
@@@
@@
@
However, trying to make this has given me a program that does something similar (but not the same):
for example, with my current program rows = 4 outputs:
@@@@
@@@
@@
@
and rows = 3 gives
@@@
@@
@
It seems that it's just missing a space (and therefore a setw and setfill), but I found 2 problems:
1. The space needs to not apply to the first line.
2. I can't get it to make a space before each row without making a space between each column.
My current code is:
#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int rows;
[Code] ....
I have tried putting in << setws and << setfills of various values but it seems to always apply to between each column as well as at the start of each row- what do I do?
View 4 Replies
View Related
Jan 20, 2015
I have a program that prints out pascal's triangle. One problem: it isn't a triangle. The output doesn't work. This is what it should print:
Code: How many rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1 and this is what it does print: Code: Enter a number of rows: 4
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
[Code]....
View 3 Replies
View Related
Dec 23, 2014
I use photos to express it. The answer is:
Code:
int main(int argc, char *argv[], int n) {
int i,j;
for (i=1;i<=n/2+1;i++) {
[Code]....
View 3 Replies
View Related
Jun 10, 2013
I am currently learning "if statements" while doing a program that calculates the area of a triangle. My problem is that the result is always "0". I am pretty sure the problem lies within my math, but how I have set it up wrong.
I am using Heron's Formula. Here it is for reference:
area=sqrt(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2
Code:
#include <stdio.h>
#include <math.h>
int main () {
float area, sideA, sideB, sideC, halfP;
[Code] ....
View 4 Replies
View Related
Mar 13, 2013
How to make triangles using c++, in nested while loops.
The triangles were:
*
**
***
****
*****
******
*******
********
*********
**********
I have made a code for this:
int counter=1;
while (counter<=10){
int counter2=1;
while (counter2<counter){
[Code] .....
I was not quite sure about this one.
View 5 Replies
View Related
May 26, 2013
i have written a program to find area of triangle, but i meet some errors,
//******area of triangle******//
#include<iostream>
using namespace std;
[Code].....
View 1 Replies
View Related
Aug 16, 2014
how can i display a pascal triangle in forloop?
Here's my code.
#include<iostream>
using namespace std;
void print(int a[3][3])
[Code].....
View 1 Replies
View Related
Feb 22, 2013
how can i print an equilateral triangle with asterisks .
View 3 Replies
View Related
Mar 7, 2015
When i set any 3 inputs length, the space should be move in right position. I try to fix the space move forward into 1 space, but don't know why it doesn't work. Specially, when the number is 4 or 5. The space didn't move 1 space.
using System;
class length{
static void Main(){
int i,j,k;
string star = "*";
string s1 ="";
string s2;
int[] nums = new int[] {3,4,5};
[Code] .....
View 2 Replies
View Related
Feb 13, 2013
i draw some object (polygon , triangle , etc.. ) and i want to move them from side to side automatically and from keyboard ...
View 1 Replies
View Related