Share 77 bài tập c++ có bản rất de hiểu

blackleopard431

New member
## 77 C ++ Bài tập có phiên bản rất dễ hiểu

### 1. Viết một chương trình để in "Xin chào thế giới!"

`` `C ++
#include <Istream>

int main () {
std :: cout << "Xin chào thế giới!"<< std :: endl;
trả lại 0;
}
`` `

### 2. Viết một chương trình để thêm hai số

`` `C ++
#include <Istream>

int main () {
int a, b;
std :: cin >> a >> b;
int sum = a + b;
std :: cout << sum << std :: endl;
trả lại 0;
}
`` `

### 3. Viết một chương trình để tìm giai thừa của một số

`` `C ++
#include <Istream>

int main () {
int n;
std :: cin >> n;
Int Factorial = 1;
for (int i = 2; i <= n; i ++) {
Factorial *= i;
}
std :: cout << factorial << std :: endl;
trả lại 0;
}
`` `

### 4. Viết một chương trình để đảo ngược một chuỗi

`` `C ++
#include <Istream>

int main () {
std :: chuỗi str;
std :: cin >> str;
std :: chuỗi đảo ngượcStr = "";
for (int i = str.length ()-1; i> = 0; i--) {
đảo ngượcStr += str ;
}
std :: cout << đảo ngược << std :: endl;
trả lại 0;
}
`` `

### 5. Viết một chương trình để kiểm tra xem một số là số nguyên tố

`` `C ++
#include <Istream>

int main () {
int n;
std :: cin >> n;
bool isprime = true;
for (int i = 2; i <= n / 2; i ++) {
if (n % i == 0) {
isprime = false;
phá vỡ;
}
}
if (isprime) {
std :: cout << "Số là số nguyên tố" << std :: endl;
} khác {
std :: cout << "Số không phải là nguyên tố" << std :: endl;
}
trả lại 0;
}
`` `

### hashtags:

* #C ++
* #Programming
* #tutorial
* #exercises
* #learnC ++
=======================================
## 77 C++ exercises with a very understandable version

### 1. Write a program to print "Hello World!"

```c++
#include <iostream>

int main() {
std::cout << "Hello World!" << std::endl;
return 0;
}
```

### 2. Write a program to add two numbers

```c++
#include <iostream>

int main() {
int a, b;
std::cin >> a >> b;
int sum = a + b;
std::cout << sum << std::endl;
return 0;
}
```

### 3. Write a program to find the factorial of a number

```c++
#include <iostream>

int main() {
int n;
std::cin >> n;
int factorial = 1;
for (int i = 2; i <= n; i++) {
factorial *= i;
}
std::cout << factorial << std::endl;
return 0;
}
```

### 4. Write a program to reverse a string

```c++
#include <iostream>

int main() {
std::string str;
std::cin >> str;
std::string reversedStr = "";
for (int i = str.length() - 1; i >= 0; i--) {
reversedStr += str;
}
std::cout << reversedStr << std::endl;
return 0;
}
```

### 5. Write a program to check if a number is prime

```c++
#include <iostream>

int main() {
int n;
std::cin >> n;
bool isPrime = true;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
std::cout << "The number is prime" << std::endl;
} else {
std::cout << "The number is not prime" << std::endl;
}
return 0;
}
```

### Hashtags:

* #C++
* #Programming
* #tutorial
* #exercises
* #learnC++
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top