Programming Articles

Page 97 of 2544

Get tuple element data types in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 885 Views

When it is required to get the tuple element of data types, the 'map' method and the 'type' method can be used.The map function applies a given function/operation to every item in an iterable (such as list, tuple). It returns a list as the result.The 'type' method returns the type of class of the argument that is passed to it.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration of the same −Examplemy_tuple = ('Hi', 23, ['there', 'Will']) print("The tuple is : ") ...

Read More

Find smallest and largest elements in singly linked list in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 991 Views

In this problem, we are given a singly linked list. Our task is to find the smallest and largest elements in single linked list.Let’s take an example to understand the problem, Inputlinked List : 5 -> 2 -> 7 -> 3 ->9 -> 1 -> 4OutputSmallest element = 1 Largest element = 9Solution ApproachA simple solution to the problem is using by traversing the linked list node by node. Prior to this, we will initialise maxElement and minElement to the value of the first element i.e. head -> data. Then we will traverse the linked list element by element. And ...

Read More

How to add two complex numbers by passing structure to a function in C language?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 7K+ Views

In order to add two complex numbers in C programming language, the user has to take two complex numbers as structure members and perform addition operation on those two numbers by creating a user-defined function.AlgorithmRefer an algorithm given below for addition of two complex numbers.Step 1: Declare struct complex with data members. Step 2: Declare name for structure and variables. Step 3: Enter real and imaginary part for first complex number at run time. Step 4: Enter real and imaginary part for second complex number at runtime Step 5: Compute addition of number1 and number2 by calling function. Go to ...

Read More

Custom sorting in list of tuples in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 849 Views

When it is required to sort the list of tuples in a customized manner, the 'sort' method can be used.The 'sort' method sorts the elements of the iterable in a specific order, i.e ascending or descending. It sorts the iterable in-place.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).A list of tuple basically contains tuples enclosed in a list.Below is a demonstration of the same −Exampledef tuple_sort(my_tup):    my_tup.sort(key = lambda x: x[1])    return my_tup my_tuple = [('Will', 100), ('John', 67), ('Harold', 86), ('Jane', ...

Read More

Find smallest number with given number of digits and sum of digits in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given two values that are the sum (denoting the sum of digits) and digit (denoting the number of digits). Our task is to find the smallest number with a given number of digits and sum of digits.Let’s take an example to understand the problem, Inputsum = 15, dgiti = 2Output69ExplanationAll 2 digits numbers with sum 15 are : 69, 78, 87, 96.Solution ApproachA simple solution to the problem is by considering all the numbers with digit count as digit and find the smallest number whose sum of digit is equal to the sum.An efficient solution ...

Read More

Sort lists in tuple in Python

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 394 Views

When it is required to sort the lists in a tuple, the 'tuple' method, the 'sorted' method and a generator expression can be used.The 'sorted' method is used to sort the elements of a list. It is a built-in function, that returns the sorted list.Generator is a simple way of creating iterators. It automatically implements a class with '__iter__()' and '__next__()' methods and keeps track of the internal states, as well as raises 'StopIteration' exception when no values are present that could be returned.The 'tuple' method takes an iterable as argument, and converts it into a tuple type.A list can ...

Read More

Find smallest permutation of given number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 872 Views

In this problem, we are given a large number N. Our task is to find the smallest permutation of a given number.Let’s take an example to understand the problem, InputN = 4529016Output1024569Solution ApproachA simple solution to the problem is by storing the long integer value to a string. Then we will sort the string which is our result. But if there are any leading zeros, we will shift them after the first non zero value.Program to illustrate the working of our solution, Example#include using namespace std; string smallestNumPer(string s) {    int len = s.length();    sort(s.begin(), s.end());   ...

Read More

Python Program to Implement Shell Sort

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

When it is required to implement shell sort, a function is defined, and this takes a list and the length of the list as arguments. This list is sorted up to a specific number of elements, wherein the number of elements is the largest value. This is done until the number of elements has the smallest value.This is done for all sub-lists in the list, and all these sub-lists are sorted.A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).Below is a demonstration of the same −Exampledef ...

Read More

Find speed of man from speed of stream and ratio of time with up and down streams in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 188 Views

In this problem, we are given two values S and N denoting the speed of stream in Km/h and ratio of time with up and down streams. Our task is to Find speed of man from the speed of stream and ratio of time with up and down streams.Let’s take an example to understand the problem, InputS = 5, N = 2Output15Solution ApproachA simple solution to the problem is by using the mathematical formula for the rowing problems. So, let’s see how the formula will work −speed of man = x km/h speed of stream = S km/h speed of ...

Read More

C program to generate an electricity bill

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 10K+ Views

Based on the units consumed by the user, the electricity bill is generated. If number of units consumed are more then, the rate of a unit charge will also increase.The logic applied if minimum units are consumed by the user is as follows −if (units < 50){    amt = units * 3.50;    unitcharg = 25; }The logic applied if units are in between 50 to 100 is given below −else if (units

Read More
Showing 961–970 of 25,433 articles
« Prev 1 95 96 97 98 99 2544 Next »
Advertisements