Important C++ Practical Programs
Important C++ Practical Programs
**Algorithm:**
1. Start
5. Stop.
**Code:**
#include <iostream>
int main() {
int a, b, sum;
sum = a + b;
return 0;
**Output:**
| Input | Output |
|-------|--------|
**Algorithm:**
1. Start
2. Input a number, n.
3. Initialize factorial as 1.
6. Stop.
**Code:**
#include <iostream>
int main() {
int n, factorial = 1;
cin >> n;
factorial *= i;
return 0;
}
**Output:**
| Input | Output |
|-------|----------------|
| n=5 | Factorial=120 |
3. Fibonacci Series
**Algorithm:**
1. Start
4. Use a loop to calculate the next term as t1+t2 and update t1 and t2.
6. Stop.
**Code:**
#include <iostream>
int main() {
int n, t1 = 0, t2 = 1, nextTerm;
cin >> n;
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
return 0;
}
**Output:**
| Input | Output |
|-------|-----------------|
| n=5 | 0 1 1 2 3 |
4. Prime Number Check
**Algorithm:**
1. Start
2. Input a number, n.
7. Stop.
**Code:**
#include <iostream>
int main() {
int n, i;
cin >> n;
if (n <= 1) {
isPrime = false;
} else {
isPrime = false;
break;
if (isPrime)
else
return 0;
**Output:**
| Input | Output |
|-------|-----------------------|