Sudhir sharma has Published 1206 Articles

Write an iterative O(Log y) function for pow(x, y) in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:57:56

421 Views

In this problem, we are given two integers x and y. Our task is to create a function that will be equivalent to pow(x, y) using an iterative approach that will complete the task in time complexity of 0(Log y).Let’s take a few examples to understand the problem, Inputx = ... Read More

Write a program to reverse digits of a number in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:41:46

491 Views

A program to reverse digits of a number will interchange the position of the digits and reverse there order.Let’s suppose be a number abcde the reverse will be edcba.Let’s take an example to understand the problem, Inputn = 786521Output125687To reverse digits of the number, we will take each digit of ... Read More

Write an Efficient C Program to Reverse Bits of a Number in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:29:53

831 Views

In this problem, we are given an unsigned integer n. Our task is to create a program that returns the number which is generated by reversing all the bits of the number.Let’s take an example to understand the problem, Inputn = 1Output2147483648Explanationbinary of 1 is 000...0001, the reverse is 100...0000.To ... Read More

Write an Efficient Method to Check if a Number is Multiple of 3 in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:23:18

949 Views

Here, we need to write a program that is used to check if the given number is a multiple of 3 or not.A general solution is a trivial solution, adding all the digits of the number and if the sum is a multiple of three then the number is divisible ... Read More

Write Code to Determine if Two Trees are Identical in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:17:27

250 Views

In this problem, we are given two trees. Our task is to write a code to check whether the two trees are identical or not.Two trees are said to be identical if elements of the arrays have the same value and orientation.ExampleAs both of the trees have the same values ... Read More

Writing C/C++ code efficiently in Competitive programming

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:17:18

271 Views

In competitive programming, the most important thing is an effective code. Optimized and faster code is important and can make a difference in the ranks of the programmer.To write an effective c/c++ code in competitive programming, here are some effective tools for writing c/c++ code efficiently, First, let’s recall some ... Read More

Write your own atoi() in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:11:28

508 Views

atoi() function in c programming language is used to handle string to integer conversion. The function takes a string as an input and returns the value in integer type.Syntaxint atoi(const char string)Parameters Accepted − The atio() function accepted a string as an input which will be converted into integer equivalent.Return ... Read More

Write your own memcpy() and memmove() in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 13:07:34

634 Views

memcpy() function is an inbuilt function that is used to copy data from source location to destination location.Prototype of memcpy function −void * memcpy(void *destination_location, void *source_location, size_t size)We will character by character copy data from source to destination.Program to show the implementation of the solution, Example Live Demo#include #include void ... Read More

Writing OS Independent Code in C/C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 12:42:29

295 Views

A program that can interact with the operating system irrespective of the OS on which it runs.Most of the compilers of c/c++ have the power to define macros that detect OS.Some Macros of GCC compiler are −_WIN32: macros for 32 bit and 64-bit Windows OS._WIN64: macros for 64-bit Windows OS._UNIX: ... Read More

XOR of a submatrix queries in C++

sudhir sharma

sudhir sharma

Updated on 17-Apr-2020 12:41:02

95 Views

In this problem, we are given a N x N matrix and some queries, each query contains the top-left and bottom-right corner of the submatrix created from this matrix. Our task is to find the XOR of all elements of the submatrix defined by the querries.Let’s take an example to ... Read More

Advertisements