Found 34494 Articles for Programming

C++ Program to Add Two Numbers

karthikeya Boyini
Updated on 23-Jun-2020 16:34:18

11K+ Views

Addition is a basic arithmetic operation. The program to add two numbers performs addition of two numbers and prints their sum on screen.A program that demonstrates addition of two numbers is given as follows −Example Live Demo#include using namespace std; int main() {    int num1=15 ,num2=10, sum;    sum = num1 + num2;    cout

C++ Program To Convert Decimal Number to Binary

Samual Sam
Updated on 23-Jun-2020 16:35:30

4K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the decimal number is in the decimal numeral system. The binary number is in base 2 while the decimal number is in base 10. Examples of decimal numbers and their corresponding binary numbers are as follows −Decimal NumberBinary Number1501111100101018100102711011A program that converts the decimal numbers into binary is as follows −Example Live Demo#include using namespace std; void DecimalToBinary(int n) {    int binaryNumber[100], num=n;    int i = 0;    while (n > 0) {       binaryNumber[i] = n % 2;       n = n / 2;       i++;    }    cout

C++ Program to Print Number Entered by User

karthikeya Boyini
Updated on 23-Jun-2020 16:36:19

4K+ Views

The objects “cin” and “cout” are used in C++ for input and output respectively. cin is an instance of the istream class and is attached to the standard input device such as the keyboard. cout is an instance of the ostream class and is connected to the standard output device such as the display screen.A program that prints the number entered by the user is as follows −Example Live Demo#include using namespace std; int main() {    int num;    coutnum;    cout

Python program to check whether two lists are circularly identical

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

598 Views

Here two lists are given. Our task is to check and found weather two given lists are circularly identical or not. Example Input : A = [100, 100, 10, 10, 100] B = [100, 100, 100, 10, 10] Output : True Explanation True as when these elements in the list will circularly rotate then they would be similar to other given list Algorithm Step 1: Create First and Second List. Step 2: Then Lists are converted to map. Step 3: join () method is used for converting the ... Read More

C++ Program to Check Whether a Number is Prime or Not

Samual Sam
Updated on 23-Jun-2020 16:36:59

3K+ Views

A prime number is a whole number that is greater than one and the only factors of a prime number should be one and itself. Some of the first prime numbers are −2, 3, 5, 7, 11, 13 ,17The program to check if a number is prime or not is as follows.Example Live Demo#include using namespace std; int main() {    int n=17, i, flag = 0;    for(i=2; i

C++ Program to Display Factors of a Number

karthikeya Boyini
Updated on 23-Jun-2020 16:38:25

10K+ Views

Factors are those numbers that are multiplied to get a number.For example: 5 and 3 are factors of 15 as 5*3=15. Similarly other factors of 15 are 1 and 15 as 15*1=15.The program to display the factors of a number are given as follows.Example Live Demo#include using namespace std; int main() {    int num = 20, i;    cout

Python Program to print unique values from a list

Sarika Singh
Updated on 23-Nov-2022 08:24:42

2K+ Views

List is a built-in data structure in python which functions like a dynamically sized array. Lists are created by putting elements in square brackets ‘[element 1, element 2, ….]’. Elements present in list are indexed and the indexing starts from [0]. List has the following properties − List is mutable meaning that elements can be added, removed or changed from a list after its creation. List is ordered, so adding new elements to the list will not change the order of existing elements. List allows for entry of duplicate elements since each element has a unique index. A single ... Read More

C++ Program to Display Fibonacci Series

Samual Sam
Updated on 23-Jun-2020 16:24:22

14K+ Views

The fibonacci series contains numbers in which each term is the sum of the previous two terms. This creates the following integer sequence −0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377…….The recurrence relation that defines the fibonacci numbers is as follows −F(n) = F(n-1) + F(n-2) F(0)=0 F(1)=1Programs to Display Fibonacci SeriesThere are two methods to display fibonacci series i.e. using dynamic programming and recursive programming. These are further explained as follows −Dynamic ProgrammingExample#include using namespace std; void fib(int n) {    int f[n];    int i;    f[0] = 0;    f[1] ... Read More

C++ "Hello, World!" Program

karthikeya Boyini
Updated on 23-Jun-2020 16:25:01

14K+ Views

C++ is a general purpose programming language that supports procedural, object-oriented and generic programming. C++ is a superset of C and all valid C programs are valid in C++ as well.C++ supports object oriented programming with features such as data hiding, encapsulation, inheritance, polymorphism etc.Let us see the first C++ program that prints Hello, World!.Example#include using namespace std; int main() {    cout

Python program to sort a tuple by its float element

Sarika Singh
Updated on 23-Nov-2022 07:33:43

1K+ Views

This article will demonstrate how write a Python program to sort a tuple (made up of float elements) using its float elements. Here, we'll look at both how to sort using the in-built sorted() function and how to sort using the in-place method of sorting. Input-Output Scenarios Following is an input and its output scenario determining the sorting of a tuple by its float element − Scenario-1 Input: tuple = [(‘Dengu’, ’54.865’), (‘Malaria’, ‘345.743’), (‘Corona’, ‘456.864’), (‘Typhoid’, ‘35.285’), (‘Jaundice’, ’83.367’)] Output: [(‘Corona’, ‘456.864’), (‘Malaria’, ‘345.743’), (‘Jaundice’, ’83.367’), (‘Dengu’, ’54.865’), (‘Typhoid’, ‘35.285’)] In the above scenario we can see that ... Read More

Advertisements