Sam Ap 3.2
Sam Ap 3.2
Sam Ap 3.2
Experiment 3.2
Student Name: Samarth Maheshwari UID: 21BCS10260
Branch: BE-CSE Section/Group: IoT-613A
Semester:5 Date: 30-10-2023
Subject Name: Advance Programming Lab Subject Code: 21CSP-314
Aim:
1.WAP to check palindrome
2.WAP to solve Fibonacci sequence
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.
2. 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:
Program 1:-
#include<bits/stdc++.h> using
namespace std; typedef
long long int ll;
#define mp make_pair
#define pb push_back
#define pob pop_back()
#define mod 1000000007
#define max INT_MAX
#define min INT_MIN
#define fi first
#define se second
Program 2:-
#include <iostream>
using namespace std;
int fibonacci(int n) {
if (n ==0)
return 0; else if
(n== 1) return
1;
else return fibonacci(n-1)
+fibonacci (n-2);
} int main() { int
n; cin >> n;
cout <<
fibonacci(n);
return 0;
}
Output:
Program 1
Program 2
Learning Outcomes:
• Understand the problem of converting a number into a binary palindrome and the
significance of palindrome representations.
• Learn about the recursive nature of the Fibonacci sequence, where each term depends on the
previous two terms.
• Learn how to approach and solve a problem that involves making decisions to modify a
numerical value efficiently.