Professional Documents
Culture Documents
CS Practical File 2
CS Practical File 2
CS Practical File 2
CODES
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
elif nterms == 1:
print(n1)
else:
print("Fibonacci sequence:")
print(n1)
nth = n1 + n2
# update values
n1 = n2
n2 = nth
count += 1
RESULTS
How many terms? 10
Fibonacci sequence:
1
1
13
21
34
CODES :
# Python program to check if the number is an Armstrong number or not
# initialize sum
sum = 0
RESULTS
Enter a number: 10
10 is not an Armstrong number
>
CODES:
int main() {
scanf("%d", &n);
originalN = n;
while (n != 0) {
remainder = n % 10;
n /= 10;
}
// palindrome if orignalN and reversedN are equal
if (originalN == reversedN)
else
return 0;
RESULTS
Enter an integer: 1001
1001 is a palindrome.
4. Write the program to accept a number and find out whether it is a perfect
number or not .
CODES:
RESULTS:
Please Enter any Number:6
6 is a Perfect Number
5. Write a program to accept a decimal number and display its binary
number.
CODES:
if num > 1:
decimalToBinary(num // 2)
print(num % 2, end='')
number = int(input("Enter any decimal number: "))
decimalToBinary(number)
RESULTS:
Enter any decimal number:42
101010
CODES:
# Python program to find the factorial of a number provided by the user.
num = 7
factorial = 1
elif num == 0:
else:
factorial = factorial*i
RESULTS:
The factorial of 7 is 5040
>
# initialisation
i = 2;sum = 1;
i += 1
else :
print(n,"is not a perfect number")
RESULTS:
First run:
Enter a number: 28
28 is a perfect number
Second run:
Enter a number: 14
14 is not a perfect number
- BY : Atul Ratan
Class : XI - A