Activity
1. Write a program to ask user input the radius of a circle and then find its area.
2. Write a program to ask user input the side of a square and then find its area and
perimeter.
3. Write a program to convert meters into centimeters and vice versa. (1 m = 100 cm)
Answers
1.
class Circle
{
public static void main(String args[])
{
double radius=Double.parseDouble(args[0]);
System.out.println("Area: "+(22/7 * radius * radius));
System.out.println("Perimeter: "+(2 * 22/7 * radius));
}
}
2.
/*
* C Program to calculate area of a square
*/
#include <stdio.h>
#include <conio.h>
int main(){
float side, area;
printf("Enter length of side of square\n");
scanf("%f", &side);
/* Area of Square = Side X Side */
area = side * side;
printf("Area of square : %0.4f\n", area);
getch();
return 0;
}
3.
// C++ program to convert centimeter
// into meter and kilometer
#include <bits/stdc++.h>
using namespace std;
int main()
{
float cm, meter, kilometer;
cm = 1000;
// Converting centimeter into meter
// and kilometer
meter = cm / 100.0;
kilometer = cm / 100000.0;
cout << "Length in meter = " << meter << "m"
<< "\n";
cout << "Length in Kilometer = " << kilometer << "km"
<< "\n";
return 0;
}