//Perhaps this is what you want.
//@author Rosencrantz
import java.util.Scanner;
class TriangleFun
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
boolean done = false;
while(true)
{
System.out.print("Calculate AREA or PERIMETER? Type DONE to quit.");
String input = scan.nextLine().trim();
if(input.equalsIgnoreCase("DONE"))
break;
if(input.equalsIgnoreCase("AREA"))
{
System.out.print("Enter the base length: ");
double base = scan.nextDouble();
System.out.print("Enter the height: ");
double height = scan.nextDouble();
System.out.println("Area is: " + (1/2.0) * base * height);
}
else
{
System.out.print("Enter length of side 1: ");
double length1 = scan.nextDouble();
System.out.print("Enter length of side 2: ");
double length2 = scan.nextDouble();
System.out.print("Enter length of side 3: ");
double length3 = scan.nextDouble();
System.out.println("Perimeter is: " + (length1 + length2 + length3));
}
scan.nextLine();
}
}
}
//A better edited version is in the links
Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);Compute means to calculate. What do you want to "compute", if you already know it is 2? If you want to show the value:System.out.println("Your number is " + 2);
Please refer to Wikipedia where there is a full C example to do specifically this. I imagine whoever had the homework assignment before you posted their answer there.
1. Design an algorithm to compute sum of the squares of n numbers?
There is a function which can do it for you. You have to include math.h in headers. And then use the function pow(x, y) which returns a value of type double (x and y are double too).pow(x, y) = x to the power of y.
There is no such function in C++ as the implementation is hardware-dependant and would require a low-level operating system API call. C++ is designed to be as generic as possible, thus there are no built-in functions to cater for this. See related links below for an article which describes how such information can be obtained.
Compute = calculate; perimeter = measurement of the outside edge.
-- Measure or calculate the length of one side. -- Measure or calculate the length of another side. -- Measure or calculate the length of the only remaining side. -- Add the three numbers. The sum is the perimeter of the triangle. ----------------------------------- The perimeter is the sum of all three sides. Sometimes it is unnecessary to compute each side length; all we care about is the sum.
math
add the lengths of all the sides
creat a flowchart that will compute for the area and perimeter of a square?
an example of solving a right triangle
we compute it by using their differences
Usually that means figure out the area and perimeter. Remember the perimeter is adding all sides like putting up and fence. And the area is x (multiplying) the 2 sides
There is no simple formula: you just need to add together the lengths of each of the 4 sides.
{A program to compute the area of a triangle} {by Ogboin W. Meshach} Var; b,h:real; BEGIN Writeln('Triangle'); Write('Base: '); Readln(base); Write('Height: '); Readln(height); area:=0.5*base*height; Writeln('Area: ', area :0:2); End.
its derivative is easy to compute
using the function norm(A,x) where A is the matrix/vector that you have to compute the norm for and x can be 1,2,inf, or 'fro' to compute the 1-norm, 2-norm, infinite-norm and frobenius norm respectively.