Share bài tập kiểu xâu - tin học 11 c++

## Bài tập - Tin học 11 C ++

1. Viết một chương trình in 100 số Fibonacci đầu tiên.

`` `C ++
#include <Istream>

sử dụng không gian tên STD;

int main () {
// Xác định hai số Fibonacci đầu tiên.
int a = 0;
int b = 1;

// In 100 số Fibonacci đầu tiên.
for (int i = 0; i <100; i ++) {
// Tính số Fibonacci tiếp theo.
int c = a + b;

// In số Fibonacci.
cout << c << endl;

// Cập nhật A và B cho lần lặp tiếp theo.
a = b;
B = C;
}

trả lại 0;
}
`` `

2. Viết một chương trình tính tổng của 100 số tự nhiên đầu tiên.

`` `C ++
#include <Istream>

sử dụng không gian tên STD;

int main () {
// Xác định tổng của 100 số tự nhiên đầu tiên.
int sum = 0;

// lặp lại trên 100 số tự nhiên đầu tiên.
for (int i = 1; i <= 100; i ++) {
// Thêm số hiện tại vào tổng.
tổng += i;
}

// In tổng của 100 số tự nhiên đầu tiên.
cout << "Tổng của 100 số tự nhiên đầu tiên là" << sum << endl;

trả lại 0;
}
`` `

3. Viết một chương trình giải phương trình bậc hai `AX^2 + BX + C = 0`.

`` `C ++
#include <Istream>

sử dụng không gian tên STD;

int main () {
// Xác định các hệ số của phương trình bậc hai.
Nhân đôi A, B, C;

// Đọc các hệ số của phương trình bậc hai từ người dùng.
cout << "Nhập các hệ số của phương trình bậc hai:" << endl;
cin >> a >> b >> c;

// Giải phương trình bậc hai.
gấp đôi x1, x2;

if (a == 0) {
// Phương trình là tuyến tính.
x1 = -c / b;
} khác {
// Phương trình là bậc hai.
Double phân biệt đối xử = b^2 - 4ac;

if (phân biệt đối xử> 0) {
// Phương trình có hai gốc thực.
x1 = (-b + sqrt (phân biệt đối xử)) / 2a;
x2 = (-b - sqrt (phân biệt đối xử)) / 2a;
} if if (phân biệt đối xử == 0) {
// Phương trình có một gốc thực.
x1 = -b / 2a;
} khác {
// Phương trình không có gốc thực.
x1 = x2 = 0;
}
}

// In rễ của phương trình bậc hai.
cout << "Rễ của phương trình bậc hai là" << x1 << "và" << x2 << endl;

trả lại 0;
}
`` `

4. Viết một chương trình in mẫu sau:

`` `
*
**
***
****
*****
`` `

`` `C ++
#include <Istream>

sử dụng không gian tên STD;

int main () {
// Xác định số lượng hàng trong mẫu.
int n = 5;

// lặp lại trên các hàng của mẫu.
for (int i = 0; i <n; i ++) {
// In số dấu hoa thị trong hàng hiện tại.
for (int j = 0; j <= i; j ++) {
cout << "*";
}

// In một ký tự mới.
cout << endl;
}

trả lại 0;
=======================================
## Exercises - Informatics 11 C++

1. Write a program that prints the first 100 Fibonacci numbers.

```c++
#include <iostream>

using namespace std;

int main() {
// Define the first two Fibonacci numbers.
int a = 0;
int b = 1;

// Print the first 100 Fibonacci numbers.
for (int i = 0; i < 100; i++) {
// Calculate the next Fibonacci number.
int c = a + b;

// Print the Fibonacci number.
cout << c << endl;

// Update a and b for the next iteration.
a = b;
b = c;
}

return 0;
}
```

2. Write a program that computes the sum of the first 100 natural numbers.

```c++
#include <iostream>

using namespace std;

int main() {
// Define the sum of the first 100 natural numbers.
int sum = 0;

// Iterate over the first 100 natural numbers.
for (int i = 1; i <= 100; i++) {
// Add the current number to the sum.
sum += i;
}

// Print the sum of the first 100 natural numbers.
cout << "The sum of the first 100 natural numbers is " << sum << endl;

return 0;
}
```

3. Write a program that solves the quadratic equation `ax^2 + bx + c = 0`.

```c++
#include <iostream>

using namespace std;

int main() {
// Define the coefficients of the quadratic equation.
double a, b, c;

// Read the coefficients of the quadratic equation from the user.
cout << "Enter the coefficients of the quadratic equation: " << endl;
cin >> a >> b >> c;

// Solve the quadratic equation.
double x1, x2;

if (a == 0) {
// The equation is linear.
x1 = -c / b;
} else {
// The equation is quadratic.
double discriminant = b^2 - 4ac;

if (discriminant > 0) {
// The equation has two real roots.
x1 = (-b + sqrt(discriminant)) / 2a;
x2 = (-b - sqrt(discriminant)) / 2a;
} else if (discriminant == 0) {
// The equation has one real root.
x1 = -b / 2a;
} else {
// The equation has no real roots.
x1 = x2 = 0;
}
}

// Print the roots of the quadratic equation.
cout << "The roots of the quadratic equation are " << x1 << " and " << x2 << endl;

return 0;
}
```

4. Write a program that prints the following pattern:

```
*
**
***
****
*****
```

```c++
#include <iostream>

using namespace std;

int main() {
// Define the number of rows in the pattern.
int n = 5;

// Iterate over the rows of the pattern.
for (int i = 0; i < n; i++) {
// Print the number of asterisks in the current row.
for (int j = 0; j <= i; j++) {
cout << "*";
}

// Print a newline character.
cout << endl;
}

return 0;
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top