Find Factorial of a Number Using Dynamic Programming in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

6K+ Views

The factorial of a positive integer n is equal to 1*2*3*...n. Factorial of a negative number does not exist. Here a C++ program is given to find out the factorial of a given input using dynamic programming.AlgorithmBegin    fact(int n):       Read the number n       Initialize       i = 1, result[1000] = {0}       result[0] = 1       for i = 1 to n          result[i] = I * result[i-1]    Print result EndExample Code#include using namespace std; int result[1000] = {0}; int fact(int n) {    if (n >= 0) {       result[0] = 1;       for (int i = 1; i

C++11 Features in Visual Studio 2015

George John
Updated on 30-Jul-2019 22:30:23

376 Views

C++11 is a version of standard C++ language. It was approved by International Organization for Standardization (ISO) on 12 August 2011 then C++14 and C++17. C++11 makes several additions to the core language. Visual C++ implements the vast majority of features in C++11. Some of the following C++11 features in Visual Studio 2015 − nullptr − In the previous nullptr, zero used to be the value and it had a drawback ofimplicit conversion to integral value. The null pointer literal is represented by std::nullptr_t. In this nullptr, no implicit conversion exists. Lambdas − The lambda expression allows to ... Read More

Instruction Type ADC R in 8085 Microprocessor

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

7K+ Views

In 8085 assembly language coding, sometimes there is a requirement to add two numbers and where each of these numbers are having several Bytes in size. As example, let us add the following two 16-bit numbers. 1 10 50H A0 F1H ------ B1 01H In this example, the addition of 50H and F1H results in a sum of 01H with a carry of 1. Now, we are supposed to add 10H and A0H along with this carry of 1. To carry out ... Read More

Python Alternate __repr__ Implementation

George John
Updated on 30-Jul-2019 22:30:23

490 Views

In Python, if we want to limit the large amount of data from displaying, we can use the reprlib module. To use this module, we should import it using. import reprlib There are different classes and methods related to reprlib. These are − Class reprlib.Repr The Repr class provides formatting services. It creates functions like built-in repr(). In this class we can add size limits and different object types. Method reprlib.repr(object) This method is used to return string like built-in repr() method, But in this case there is a limits on most sizes. Repr Objects The Repr object ... Read More

Color Game Using Tkinter in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

2K+ Views

For developing GUI applications tkinter is very popular and easy. Using tkinter easily develop GUI games. Here also we are trying to develop color game. In this game the player has to enter color of the word that appears on the screen and hence the score increases by one, the total time to play this game is 30 seconds and colors used in this game are Red, Blue, Green, Pink, Black, Yellow, Orange, White, Purple and Brown. The interface will display name of different colors in different colors. User has to identify the color and enter the correct color name ... Read More

Stack in Java Programming

Arushi
Updated on 30-Jul-2019 22:30:23

292 Views

Stack is a subclass of Vector that implements a standard last-in, first-out stack. Stack only defines the default constructor, which creates an empty stack. Stack includes all the methods defined by Vector, and adds several of its own. Stack( ) Apart from the methods inherited from its parent class Vector, Stack defines the following methods − Sr.No. Method & Description 1 boolean empty() Tests if this stack is empty. Returns true if the stack is empty, and returns false if the stack contains elements. 2 Object peek( ) Returns the element ... Read More

Instruction Type ACI D8 in 8085 Microprocessor

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

In 8085 Instruction set, ACI is a mnemonic which stands for 'Add with Carry Immediate to Accumulator' and here “d8” stands for any 8-bit or 1-Bytedata. This instruction is actually meant for adding one 8-bit immediate data or operand to the Accumulator along with the carry value. The result of the addition will be stored in the Accumulator itself and replacing initial value of the Accumulator. As it is an arithmetic instruction, so the flags are affected based on the result. It holds 2-Bytes in the memory. Mnemonics, Operand Opcode(in HEX) Bytes ACI Data CE 2 ... Read More

Secure Hashes and Message Digest in Python

Chandu yadav
Updated on 30-Jul-2019 22:30:23

2K+ Views

For the secure hash and message digest process, we should use the hashlib module. This module implements a common interface for different secure hash algorithm like SHA1, SHA224, SHA256, SHA512 etc. Also the RSA’s MD5 algorithm. Older algorithms are known as the Message Digest and the new methods are called Secure Hash. To use this module, we need to import the hashlib module in the python code. import hashlib In this method, there are some predefined algorithms like md5, sha1, sha224, sha256, sha512 are present. We can add additional algorithms from the OpenSSL library. Some methods, constants of ... Read More

Python Program to Find Maximum of Three Numbers

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

10K+ Views

Given three number a b and c, our task is that we have to find the maximum element in among in given number. Example Input: a = 2, b = 4, c = 3 Output: 4 Algorithm Step 1: input three user input number. Step2: Add three numbers to list. Step 3: Using max() function to find the greatest number max(lst). Step 4: And finally we will print maximum number. Example Code def maximum(a, b, c): list = [a, b, c] return max(list) # ... Read More

Dynamically Allocate a 2D Array in C

Chandu yadav
Updated on 30-Jul-2019 22:30:23

17K+ Views

A 2D array can be dynamically allocated in C using a single pointer. This means that a memory block of size row*column*dataTypeSize is allocated using malloc and pointer arithmetic can be used to access the matrix elements. A program that demonstrates this is given as follows. Example Live Demo #include #include int main() { int row = 2, col = 3; int *arr = (int *)malloc(row * col * sizeof(int)); int i, j; for (i = 0; i < row; i++) ... Read More

Advertisements