Computer Science & Engineering: Department of
Computer Science & Engineering: Department of
Experiment 3.2
Name Ali Siddiqui UID 21BCS1713
Branch: BE-CSE Section/Group: IoT-617-B
Semester:5 Date of Performance:25-10-2023
Subject Name: Advance Programming Lab Subject Code: 21CSP-314
TASK-1
1. Aim:
1.WAP to check palindrome
2.WAP to solve Fibonacci sequence
2. Objective:
1. You are given a number . In one operation, you can either increase the value of by
1 or decrease the value of by 1. Determine the minimum number of operations
required (possibly zero) to convert number to a number such that binary
representation of is a palindrome. Note: A binary representation is said to be a
palindrome if it reads the same from left-right and right-left.
set<int> v;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
binarypalindrome(1,i-2, c);
}
cin>>t;
while (t--)
{
cin>>n;
auto ptr=v.lower_bound(n);
auto ptr2= ptr--;
if(abs(n-*ptr)<abs(n-*ptr2))
cout<<abs(n-*ptr)<<endl;
else
cout<<abs(n-*ptr2)<<endl;
}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
return 0;
}
Output:-
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
TASK-2
1. OBJECTIVE
The Fibonacci sequence appears in nature all around us, in the arrangement
of seeds in a sunflower and the spiral of a nautilus for example. The
Fibonacci sequence begins with and as its first and second terms. After these
first two elements, each subsequent element is equal to the sum of the
previous two elements. Programmatically:
2. SOURCE CODE
def fibonacci(n):
n = int(input())
k=[]
fibonacci(n)
print(k[n])
3. OUTPUT
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING