USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int height,base,area;
height=4;
base=3;
area=(height*base)/2;
printf(" the area of the triangle is: %d ", area);
// %d is use of integer type variables//
return 0;
}
USING JAVA
public static void main(String[] args)
{
int height = 4;
int base = 3;
int area = (height * base)/2 ;
System.out.println("the area of the triangle is: " + area);
}
..........................................................................................................
in both java and c the output will be
the result is: 6
...........................................................................................................
IF WE WANT THE USER TO INPUT THE NUMBERS:
USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
printf("enter the height:");
scanf("%d", &x);
printf("Enter the base:");
scanf("%d", &y);
z=(x*y)/2;
printf(" the area of the triangle is: %d ", z);
// %d is use of integer type variables//
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int firstvalue;
int secondvalue;
System.out.print("Enter the height:");
firstvalue= sc.nextInt();
System.out.print("Enter the base:");
secondvalue=sc.nextInt();
int result = (firstvalue * secondvalue)/2 ;
System.out.println("the area of the triangle is:" + result);
}
}
#include<stdio.h>
#include<conio.h>
int main()
{
int height,base,area;
height=4;
base=3;
area=(height*base)/2;
printf(" the area of the triangle is: %d ", area);
// %d is use of integer type variables//
return 0;
}
USING JAVA
public static void main(String[] args)
{
int height = 4;
int base = 3;
int area = (height * base)/2 ;
System.out.println("the area of the triangle is: " + area);
}
..........................................................................................................
in both java and c the output will be
the result is: 6
...........................................................................................................
IF WE WANT THE USER TO INPUT THE NUMBERS:
USING C
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
printf("enter the height:");
scanf("%d", &x);
printf("Enter the base:");
scanf("%d", &y);
z=(x*y)/2;
printf(" the area of the triangle is: %d ", z);
// %d is use of integer type variables//
return 0;
}
USING JAVA
import java.util.Scanner;
{
static Scanner sc= new Scanner(System.in);
public static void main(String[] args)
{
int firstvalue;
int secondvalue;
System.out.print("Enter the height:");
firstvalue= sc.nextInt();
System.out.print("Enter the base:");
secondvalue=sc.nextInt();
int result = (firstvalue * secondvalue)/2 ;
System.out.println("the area of the triangle is:" + result);
}
}






0 comments:
Post a Comment