Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Shree Amreli Jilla charitable Trust,

Surat
S.M.T Santaben Haribhai Gajera Shaikshanik Sankul
Amreli

Computer Assignment

Trivedi Harshil Vishalbhai

STD :9E
Roll No :16
Topic : Assignment ::5 (2/9/2021)
1)find area of square
Program to find the area of the square
Area of the square is the amount of space occupied by a square. Square refers to a
plane figure with four equal straight sides and four right angles.

Formula
area = width × height
Area of square will be calculated as :
area = side2
since width = height;

Algorithm
1. Define the height of any one side of the square as 's.'
2. Calculate the area of the square by multiplying s with s
3. Define the area_square as the area of the square.

#include <stdio.h>  
int main()  
{  
   int s=13;  
   int area_square=s*s;  
   printf("Area of the square=%d",area_square);  
}  

Java Program
public class shpere{

public static void main(String args[])

{
int s=13;

int area_square=s*s;

System.out.println("Area of the square="+area_square);

}
2)find area of Triangle
Program to find the area of a triangle
Explanation
Three sided polygon is known as Triangle. It has a base and an altitude(height).

Area of Triangle = ½(b × h) where b is base and h is height.

Algorithm
1. Define base and height
2. Apply in the formula.
3. Print the Area.

public class test

public static void main (String args[])

{ float b=4,h =13,area ;

area = ( b*h) / 2 ;

System.out.println("Area of Triangle is:

"+area);

}}
3)find area of circle
This is a Java Program to Calculate and Display Area of a Circle.
Formula:
Perimeter of circle=pi * radius * radius
Enter the radius of the circle as input. Now we use the given formula to calculate the
area of the circle using formula.

Here is the source code of the Java Program to Calculate and Display Area of a Circle.
The Java program is successfully compiled and run on a Windows system. The program
output is also shown below.

import java.util.Scanner;

public class Area

public static void main(String[] args)

int r;

double pi = 3.14, area;

Scanner s = new Scanner(System.in);

System.out.print("Enter radius of circle:");

r = s.nextInt();

area = pi * r * r;

System.out.println("Area of circle:"+area);
}

}
4)find area of rectangle
Program to calculate the area of the rectangle
Area of a rectangle is the amount of space occupied by the rectangle. A rectangle
can be defined as the plain figure with two adjacent sides equal in length. The 4
angles present in the rectangle are also equal. A rectangle can be divided into 4
similar square. The measurement of each interior angle in a rectangle is 90 degrees.

Area of a rectangle is the number of square units takes to fill a rectangle completely.

Formula
1. A= W x H  

where

A is the area of the rectangle


W is the width of the rectangle
H is the height of the rectangle

Algorithm
1. Define the width of the rectangle.
2. Define the Height of the rectangle.
3. Define Area of the rectangle.
4. Calculate the area of the rectangle by multiplying the width and height of the
rectangle.
5. Assign the area of the rectangle to the area variable.
6. print the area of the rectangle.

public class rectangle{


public static void main(String args[])
{
int width=5;
int height=10;
int area=width*height;
System.out.println("Area of
rectangle="+area);
}
}
5)find area and perimeter of Rectangle
This is a Java Program to Create a Simple Class to Find out the Area and Perimeter of
Rectangle.
Formula:
Perimeter of rectangle = 2 * (length + breadth)
Area of rectangle = length * breadth
Enter the length and breadth of the rectangle as input. Now we use the given formula to
calculate the area and perimeter of rectangle.

Here is the source code of the Java Program to Create a Simple Class to Find out the
Area and Perimeter of Rectangle. The Java program is successfully compiled and run on
a Windows system. The program output is also shown below.

import java.util.Scanner;
public class Area_Perimeter
{
public static void main(String[] args)
{
int l, b, perimeter, area;
Scanner s = new Scanner(System.in);
System.out.print("Enter length of rectangle:");
l = s.nextInt();
System.out.print("Enter breadth of rectangle:");
b = s.nextInt();
perimeter = 2 * (l + b);
System.out.println("Perimeter of
rectangle:"+perimeter);
area = l * b;
System.out.println("Area of rectangle:"+area);
}
}

You might also like