Server Side Programming Articles - Page 2167 of 2650

Python program to print negative numbers in a list

Pavitra
Updated on 04-Jul-2020 12:54:55

770 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a list iterable, we need to print all the negative numbers in the list.Here we will be discussing three approaches for the given problem statement.Approach 1 − Using enhanced for loopExamplelist1 = [-11, 23, -45, 23, -64, -22, -11, 24] # iteration for num in list1:    # check    if num < 0:       print(num, end = " ")Output-11 -45 -64 -22 -11Approach 2 − Using filter & lambda functionExample Live Demolist1 = [-11, 23, -45, 23, -64, -22, -11, ... Read More

Check if a large number is divisible by 9 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 08:18:34

317 Views

Here we will see how to check a number is divisible by 9 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 9, if the sum of digits is divisible by 9.Example Live Demo#include using namespace std; bool isDiv3(string num){    int n = num.length();    long sum = accumulate(begin(num), end(num), 0) - '0' * n;    if(sum % 9 == 0)       return true;       return false; } int main() {    string num = "630720";    if(isDiv3(num)){       cout

Check if a large number is divisible by 8 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 08:14:44

465 Views

Here we will see how to check a number is divisible by 8 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 8, if the number formed by last three digits are divisible by 8.Example Live Demo#include using namespace std; bool isDiv8(string num){    int n = num.length();    int last_three_digit_val = (num[n-3] - '0') * 100 + (num[n-2] - '0') * 10 + ((num[n-1] - '0'));    if(last_three_digit_val % 8 == 0)       return true;       return false; } int main() {    string num = "1754586672360";    if(isDiv8(num)){       cout

Python program to print even numbers in a list

Harshit Sachan
Updated on 13-Oct-2022 12:03:38

13K+ Views

Python Programming Language is one of the most efficient and user-friendly programming language and have endless uses and applications. Lists declared in Python are analogous to dynamically sized arrays in other programming languages (vector in C++ and ArrayList in Java). A list is simply a collection of items enclosed by [] and separated by commas. In this tutorial, we will learn about the solution and approach to find out all even numbers in a given list using Python. List is one of the most fundamental data structures in python. They are widely used and they store similar contiguous data. A ... Read More

Check if a large number is divisible by 75 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 08:11:34

216 Views

Here we will see how to check a number is divisible by 75 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 75, when the number is divisible by 3 and also divisible by 25. if the sum of digits is divisible by 3, then the number is divisible by 3, and if last two digits are divisible by 25, then the number is divisible by 25.Example Live Demo#include using namespace std; bool isDiv75(string num){    int n = num.length();    long sum = accumulate(begin(num), end(num), ... Read More

Python program to print even length words in a string

Harshit Sachan
Updated on 13-Oct-2022 11:58:05

6K+ Views

In Python Programming Language, Length is the concept of calculating the entire range of the string that begins from the first character of the string till the last character of the string. Printing and calculating even length in a string is a basic exercise in the programing language. In this tutorial, we will learn about the solution and approach to find out all words in a string having even length. A number is considered odd if it divides by 2 evenly, i.e. leaving no remainder. This property should hold for the length of the words we need. So the ... Read More

Python program to print all odd numbers in a range

Pavitra
Updated on 27-Sep-2019 08:05:27

966 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statementGiven a range, we need to print all the odd numbers in the given range.The brute-force approach is discussed below −Here we apply a range-based for loop which provides all the integers available in the input interval.After this, a check condition for odd numbers is applied to filter all the even numbers.This approach takes O(n) + constant time of comparison.Now let’s see the implementation below −Examplestart, end = 10, 29 # iteration for num in range(start, end + 1):    # check   ... Read More

Check if a large number is divisible by 5 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 08:09:21

605 Views

Here we will see how to check a number is divisible by 5 or not. In this case the number is very large number. So we put the number as string.To check whether a number is divisible by 5, So to check divisibility by 5, we have to see the last number is 0 or 5.Example Live Demo#include using namespace std; bool isDiv5(string num){    int n = num.length();    if(num[n - 1] != '5' && num[n - 1] != '0')    return false;    return true; } int main() {    string num = "154484585745184258458158245285265";    if(isDiv5(num)){       cout

Check if a large number is divisible by 3 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 08:04:05

478 Views

Here we will see how to check a number is divisible by 3 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 3, if the sum of digits is divisible by 3.Example Live Demo#include using namespace std; bool isDiv3(string num){    int n = num.length();    long sum = accumulate(begin(num), end(num), 0) - '0' * n;    if(sum % 3 == 0)       return true;       return false; } int main() {    string num = "3635883959606670431112222";    if(isDiv3(num)){       cout

Check if a large number is divisible by 25 or not in C++

Arnab Chakraborty
Updated on 27-Sep-2019 07:58:01

218 Views

Here we will see how to check a number is divisible by 25 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 25, when the last two digits are 00, or they are divisible by 25.Example Live Demo#include using namespace std; bool isDiv25(string num){    int n = num.length();    int last_two_digit_val = (num[n-2] - '0') * 10 + ((num[n-1] - '0'));    if(last_two_digit_val % 25 == 0)       return true;       return false; } int main() {    string num = "451851549333150";    if(isDiv25(num)){       cout

Advertisements