0% found this document useful (0 votes)
2 views

Code

The document contains code snippets demonstrating different algorithms including finding the minimum and maximum of a set of numbers, printing the first 16 Fibonacci numbers, calculating the square root of a number using the Babylonia method, and calculating the square root of a 4 digit number formed by user input.

Uploaded by

canphong05
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code

The document contains code snippets demonstrating different algorithms including finding the minimum and maximum of a set of numbers, printing the first 16 Fibonacci numbers, calculating the square root of a number using the Babylonia method, and calculating the square root of a 4 digit number formed by user input.

Uploaded by

canphong05
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* 13.1.07.

int n;
int min = INT_MAX, max = INT_MIN;
cin >> n;
while (n != 0) {
if (n < min) {
min = n;
}
if (n > max) {
max = n;
}
cin >> n;
}
cout << "So nho nhat la: " << min << endl;
cout << "So lon nhat la: " << max << endl;
*/

/* 13.1.09.
int n = 16;
cout << n << " so dau tien cua day Fibonacci la: ";
for (int i = 1; i <= n; i++) {
if (i == 1 || i == 2) {
cout << 1 << " ";
}
else {
int j = 3, a = 0, a1 = 1, a2 = 1;
while (j <= i) {
a = a1 + a2;
a1 = a2;
a2 = a;
j++;
}
cout << a << " ";
}
}
*/

/* 13.1.11.
int n = 67;
double a = (1.0) * n / 2;
double xapxi = n - a;
double b;
while (xapxi > 1e-8) {
b = a;
a = (1.0) * (b + (1.0) * n / b) / 2;
xapxi = (b - a > 0 ? b - a : a - b);
}
cout << "Can bac hai cua " << n << " bang phuong phap Babylonia Method voi sai so 1e-8 la " << b;
*/

/* 13.1.12.
int n = 0;
for (int i = 0; i < 4; i++) {
int j;
cin >> j;
n = n * 10 + j;
}
int m = n;
double a = (1.0) * n / 2;
double xapxi = n - a;
double b;
while (xapxi > 1e-8) {
b = a;
a = (1.0) * (b + (1.0) * n / b) / 2;
xapxi = (b - a > 0 ? b - a : a - b);
}
cout << "Can bac hai cua so nguyen " << m << " tao thanh tu 4 chu so la " << b << endl;
*/

You might also like