To draw a random triangle.... Declare six variables.... H1 and V1 H2 and V2 H3 and V3 Then using the random function apply the random to the height of your form - this will be H1 Do the same with the width of the form - this will be V1 -- do this twice more, for H2 and V2 - and then for H3 and V3.. Then draw a line from (H1, V1) to (H2, V2) Draw another line from (H1, V1) to (H3, V3) Draw the last line from (H2, V2) to (H3, V3) -- I can't guarantee it will look great, but it _will_ be a triangle. ==== To draw a specific triangle you need much more coding, involving sine rule an other trigonometry.
Chat with our AI personalities
java.util.Scanner;public class Triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double base = 0;
double height = 0;
double area = 0;
System.out.print("Enter the length of base of triangle : ");
base = input.nextDouble();
System.out.print("Enter the length of height of triangle : ");
height = input.nextDouble();
area = (base * height) / 2;
System.out.println("");
System.out.println("The Area of Triangle is : "
+ area);
}
}
#include<stdio.h> #include<conio.h> void main() { float base,height,area; clrscr(); printf("\nENTER THE BASE OF TRIANGLE\t"); scanf("%f",&base); printf("\nENTER THE HEIGHT OF TRIANGLE\t"); scanf("%f",&height); area=0.5*(base*height); printf("\nTHE AREA OF TRIANGLE IS :-----%f",area); getch(); }
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c,s,area;
printf("\n Enter the three sides of triangle\n");
scanf("%f%f%f",&a,&b,&c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("\n area of the triangle is %f", area);
return 0;
}
a triangle then a square :)
write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?
Write a program that calculates the area of a triangle in QBASIC
#include <stdio.h> main() { int r,b,h; printf("Enter the value of Base and Hight"); scanf("%d%d",&b,&h); r = ((b*h)/2); printf("Area of Triangle=%d",r); }
See the related links section for a link to a JAR file containing this program.