0% found this document useful (0 votes)
2 views3 pages

CC 101 Binary

The document contains two programming problems with solutions in C++. The first problem involves converting decimal numbers to binary, while the second problem calculates the area of a circle given its center and a point on its circumference. Sample inputs and outputs are provided for both problems, along with the corresponding code implementations.

Uploaded by

Park Jiminshii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

CC 101 Binary

The document contains two programming problems with solutions in C++. The first problem involves converting decimal numbers to binary, while the second problem calculates the area of a circle given its center and a point on its circumference. Sample inputs and outputs are provided for both problems, along with the corresponding code implementations.

Uploaded by

Park Jiminshii
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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;
}

You might also like