MICAH G.
SEDIGO September 18, 2024
BSCS – 1A Computer Programming LAB
1. Problem: Write a program that will convert decimal numbers to
binary numbers.
Sample input/output
Enter Decimal number: 12
Binary Equivalent: 1100
CODE:
#include <iostream>
using namespace std;
int main ()
{
int num, count = 0, bin[100];
cout << "Enter Decimal Number: ";
cin >> num;
for (int i = 0; num > 0; i++) {
bin[i] = num % 2;
num = num / 2;
count++;
}
cout << "\Binary Equivalent: ";
for (int j = count - 1; j >= 0; j--){
cout << bin[j];
}
}
MICAH G. SEDIGO September 18, 2024
BSCS – 1A Computer Programming LAB
2. Problem: Given the Cartesian plane coordinates for the center of a
circle (x1, y1) and a point on the circle’s circumference (x2, y2). Write
a program to calculate the area of the circle.
Formula for the Area is Pi r2
Distance between two points is D =
Pi = 3.14159
Sample input/output
Enter center of Circle Enter Point of Circumference
X1 = 3 X2 = 2
Y1 = 4 Y2 = 2
Area of a Circle is 15.71
CODE:
#include <iostream>
#include <cmath>
using namespace std;
const double PI = 3.14159;
double CenterofCircle(double x1,double y1,double
x2,double y2) {
return sqrt(pow(y2 - y1, 2) + pow(x2 - x1,
2));
}
double AreaofCircle(double radius) {
return PI * pow(radius, 2);
}
MICAH G. SEDIGO September 18, 2024
BSCS – 1A Computer Programming LAB
int main() {
double x1, y1, x2, y2;
cout << "Enter Center of Circle: ";
cout << "\nEnter X1: ";
cin >> x1;
cout << "Enter Y1: ";
cin >> y1;
cout <<"\nEnter Point of Circumference: ";
cout << "\nEnter X2: ";
cin >> x2;
cout << "Enter Y2: ";
cin >> y2;
double radius = CenterofCircle(x1, y1, x2,
y2);
double area = AreaofCircle(radius);
cout << "\nArea of the circle is " << area
<< endl;
return 0;
}