+ 🤩 CheatSheet for C🤩
  1. Fibonacci Number Given a number N,figure out if it is a member of fibonacci series or not.Return true if the number is memebr of fibonacci sereis else false.
    Fibonacci Series is defined by the recurrence
    F(n) = F(n-1) + F(n-2)
    where F(0) = 0 and F(1) = 1

    Input Format :
    Integer N
    Output Format :
    true or false
    Constraints :
    0 <= n <=10^4
    Sample Input 1 :
    5
    Sample Output 1 :
    true
    Sample Input 2 :
    14 Sample Output 2 :
    false
    
    #include
    using namespace std;
                
    bool isFib(int n){
        int i=1;
        int fisrtNum=0;
        int secondNum=1;
        if(n==0 || n==1){
            return true;
        }
        while(i<=n){
            int x= fisrtNum+secondNum;
            if(x==n){
                return true;
            }
            fisrtNum=secondNum;
            secondNum=x;
                
            i++;
        }
                   
        return false;
                   
    }
    int main(){
        cout<<"ENTER YOUR NUMBER: "<<endl;
        int x;
        cin>>x;
        int y= isFib(x);
        cout<<y<<endl;
    }
     
    
    
  2. This is the first item's accordion body. It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.

    This is the second item's accordion body. It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the .accordion-body, though the transition does limit overflow.
    \
  1. Palindrom Given an integer N, the task is to check whether the sum of digits of N is palindrome or not. Time Complexity: O(logN)
    Auxiliary Space: O(1)

    Input Format :
    Integer N: N = 56
    Output Format :
    YES or NO
    Explaination:
    Digit sum is (5 + 6) = 11, which is a palindrome.
    Sample Input 1 :
    56
    Sample Output 1 :
    YES
    Sample Input 2 :
    12321 Sample Output 2 :
    NO
    
              // C++ implementation of the approach
    #include 
    using namespace std;
     
    // Function to return the
    // sum of digits of n
    int digitSum(int n)
    {
        int sum = 0;
        while (n > 0) {
            sum += (n % 10);
            n /= 10;
        }
        return sum;
    }
     
    // Function that returns true
    // if n is palindrome
    bool isPalindrome(int n)
    {
        // Find the appropriate divisor
        // to extract the leading digit
        int divisor = 1;
        while (n / divisor >= 10)
            divisor *= 10;
     
        while (n != 0) {
            int leading = n / divisor;
            int trailing = n % 10;
     
            // If first and last digit
            // not same return false
            if (leading != trailing)
                return false;
     
            // Removing the leading and trailing
            // digit from number
            n = (n % divisor) / 10;
     
            // Reducing divisor by a factor
            // of 2 as 2 digits are dropped
            divisor = divisor / 100;
        }
        return true;
    }
     
    // Function that returns true if
    // the digit sum of n is palindrome
    bool isDigitSumPalindrome(int n)
    {
     
        // Sum of the digits of n
        int sum = digitSum(n);
     
        // If the digit sum is palindrome
        if (isPalindrome(sum))
            return true;
        return false;
    }
     
    // Driver code
    int main()
    {
        int n = 56;
     
        if (isDigitSumPalindrome(n))
            cout << "Yes";
        else
            cout << "No";
     
        return 0;
    }
               
              
              
  2. The first and last digits can be compared, and then the process is repeated. We require the numerical order for the first digit. Say, 12321. The leading 1 would be obtained by multiplying this by 10,000. By taking the mod with 10, you can get the trailing 1. Let's get this down to 232 now. (12321 % 10000)/10 = (2321)/10 = 232 It would then be necessary to take a 100 percent reduction off of the 10,000.