Found 35163 Articles for Programming

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

9K+ 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

13K+ 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

13K+ 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

Python program to find k'th smallest element in a 2D array

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

349 Views

One n×n user input integer matrix is given and the value of k. Our task is to find out k'th smallest element in a 2D array. Here we use heapq mudule.Heap queue (or heapq) in Python. In Python, it is available using “heapq” module. The technique of this module in python is that each time the smallest of heap element is popped (min heap).nsmallest () method is used to get n least values from a data frame or a series. Example Input Array is:: 10 20 20 40 15 45 40 30 32 33 30 50 ... Read More

Python program to generate all possible valid ID address from given string

Vikyath Ram
Updated on 30-Jul-2019 22:30:23

624 Views

String is given. String contains only digit. Our task is to check all possible valid IP address combinations. Here first we check the length of the string then split by ".". Then we check the different combination of ".". Example Input : "255011123222" It's not a valid IP address. Input : 255011345890 Valid IP address is 255.011.123.222 Algorithm Step 1: First check the length of the string. Step 2: Split the string by ".". We will place 3 dots in the given string. W, X, Y, and Z are numbers from 0-255 the numbers cannot be ... Read More

Python Program to find mirror characters in a string

Sarika Singh
Updated on 23-Nov-2022 07:25:19

2K+ Views

This article teaches you how to write a python program to find mirror characters in a string. Let us first understand what mirror characters in a string are. Two identical alphabetically positioned characters, one from the front and the other from the back, are known as mirror characters. For example, the alphabet a's mirror character is "z, " "b's" is "y, " and so on. Input-Output Scenario Following is an input and its output example of mirror characters in a string − Input: p = 3 Input string = Coding Output: Cowrmt Here, the alphabets “d”, “i”, “n”, “g” ... Read More

Calendar function in Python

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

1K+ Views

Python has an in built module called calendar which operation is related to calendar. There are some calendar functions in Python. calendar(year, w, l, c) This function shows the year, width of characters, no. of lines per week and column separations. Example print ("The calendar of 2014 is : ") print (calendar.calendar(2014, 3, 1, 4)) Output The calendar of year 2014 is : 2014 January ... Read More

Advertisements