Chap 1 Computer Problems Fbise
Chap 1 Computer Problems Fbise
Here are the solutions to the problems listed, along with their algorithms and sample code in Python.
---
**Algorithm:**
1. Start
5. Else largest = C
6. Output largest
7. Stop
**Python Code:**
```python
return A
return B
else:
return C
```
---
1. Start
3. If N % 2 == 0, print "Even"
5. Stop
**Python Code:**
```python
def check_odd_even(N):
if N % 2 == 0:
return "Even"
else:
return "Odd"
```
---
**Algorithm:**
1. Start
3. Initialize factorial = 1
5. Output factorial
6. Stop
**Python Code:**
```python
def factorial(N):
factorial = 1
factorial *= i
return factorial
```
---
**Algorithm:**
1. Start
5. Print "Prime"
6. Stop
**Python Code:**
```python
import math
def is_prime(N):
if N < 2:
if N % i == 0:
```
---
**Algorithm:**
1. Start
3. Initialize reversed = 0
4. While N > 0:
- N = N // 10
5. Output reversed
6. Stop
**Python Code:**
```python
def reverse_number(N):
reversed_num = 0
while N > 0:
N //= 10
return reversed_num
```
---
### 6. Find the Sum of Digits
**Algorithm:**
1. Start
3. Initialize sum = 0
4. While N > 0:
- N = N // 10
5. Output sum
6. Stop
**Python Code:**
```python
def sum_of_digits(N):
sum_digits = 0
while N > 0:
sum_digits += (N % 10)
N //= 10
return sum_digits
print(sum_of_digits(123)) # Output: 6
```
---
**Algorithm:**
1. Start
6. Stop
**Python Code:**
```python
def count_vowels_consonants(s):
vowels = "aeiouAEIOU"
count_v = 0
count_c = 0
for char in s:
if char.isalpha():
if char in vowels:
count_v += 1
else:
count_c += 1
```
---
**Algorithm:**
1. Start
3. While B ≠ 0:
- temp = B
-B=A%B
- A = temp
4. Output A
5. Stop
**Python Code:**
```python
while B != 0:
A, B = B, A % B
return A
```
---
**Algorithm:**
1. Start
2. Let radius be R.
- A = π * R^2
4. Output A
5. Stop
**Python Code:**
```python
import math
def area_of_circle(R):
return math.pi * (R ** 2)
```
---
**Algorithm:**
1. Start
6. Stop
**Python Code:**
```python
def is_palindrome(s):
return s == s[::-1]
```
---
**Algorithm:**
1. Start
2. Let N be the number of terms.
3. Initialize a, b = 0, 1
- print a
- temp = a + b
-a=b
- b = temp
5. Stop
**Python Code:**
```python
def fibonacci_series(N):
a, b = 0, 1
for _ in range(N):
a, b = b, a + b
print()
fibonacci_series(5) # Output: 0 1 1 2 3
```
---
**Algorithm:**
1. Start
**Python Code:**
```python
def bubble_sort(arr):
n = len(arr)
for i in range(n):
return arr
print(bubble_sort([64, 34, 25, 12, 22, 11, 90])) # Output: [11, 12, 22, 25, 34, 64, 90]
```
---
**Algorithm:**
1. Start
4. While N > 0:
- N //= 2
5. Output binary
6. Stop
**Python Code:**
```python
def decimal_to_binary(N):
binary = ""
while N > 0:
N //= 2
return binary
```
---
**Algorithm:**
1. Start
5. Output min_value
6. Stop
**Python Code:**
```python
def find_minimum(arr):
min_value = arr[0]
min_value = num
return min_value
---
**Algorithm:**
1. Start
2. Let principal (P), rate (R), and time (T) be the inputs.
- I = (P * R * T) / 100
4. Output I
5. Stop
**Python Code:**
```python
return (P * R * T) / 100
```
---