Server Side Programming Articles - Page 1779 of 2650

Program to find remainder without using modulo or % operator in C++

Ayush Gupta
Updated on 17-Sep-2020 05:03:25

2K+ Views

In this problem, we are given two numbers, N and D. Our task is to create a Program to find remainder without using modulo or % operator in C++.Problem description − We need to find the remainder that will be left after dividing the number N by D. But we cannot use the modulo or % operator for this.Let’s take an example to understand the problemInputN = 53 D = 3Output2Solution ApproachTo find the remainder, a simple approach is to find the number less than N which is the multiple of D. And the substrate the number from N. To ... Read More

Program to find remainder when large number is divided by r in C++

Ayush Gupta
Updated on 17-Sep-2020 05:05:49

536 Views

In this problem, we are given a string num which is a large number and an integer R. Our task is to create a program to find remainder when large number is divided by r in C++.Problem Description − We need to find the remainder when the number defined by the string is divided by r which is a two-digit number.Let’s take an example to understand the problemInputnum = “123423450942121” r = 54Output7Solution ApproachTo find the remainder, we obviously need to divide the number. But dividing huge numbers is a complex process so to ease up the process, we will ... Read More

Program to find remainder when large number is divided by 11 in C++

Ayush Gupta
Updated on 17-Sep-2020 05:07:47

496 Views

In this problem, we are given a string num which is a large number. Our task is to create a program to find remainder when large number is divided by 11 in C++.Problem Description − We need to find the remainder when the number defined by the string is divided by 11.Let’s take an example to understand the problemInputnum = “43212981843718452”Output7Solution ApproachTo find the remainder, we obviously need to divide the number. But dividing huge number is a complex process so to ease up the process, we will divide digit by digit. And store the remainder that follows. This process ... Read More

Program to find Prime Numbers Between given Interval in C++

Ayush Gupta
Updated on 19-May-2020 11:43:27

332 Views

In this tutorial, we will be discussing a program to find prime numbers between given intervals.For this we would be provided with two integers. Our task is to find the prime numbers in that particular range.Example Live Demo#include using namespace std; int main() {    int a, b, i, j, flag;    //getting lower range    a = 3;    //getting upper range    b = 12;    cout

Program to find Perimeter / Circumference of Square and Rectangle in C++

Ayush Gupta
Updated on 01-Oct-2020 11:22:01

523 Views

In this problem, we are given the side of a square (A) and the length and breadth of a rectangle (L and B). Our task is to create a Program to find Perimeter / Circumference of Square and Rectangle in C++.Problem Description:To find the circumference of a square, we need the side of the square (a). For that, we will use the formula for the perimeter of the square which is 4a.To find the circumference of a rectangle, we need the Length (L) and breadth (B) of the rectangle. For that, we will use the formula for the perimeter of ... Read More

Program to find parity in C++

Ayush Gupta
Updated on 19-May-2020 11:38:59

425 Views

In this tutorial, we will be discussing a program to find parity.For this we will be provided with a number. Our task is to find its parity i.e count of whether the number of ones are odd or even.Example Live Demo# include # define bool int using namespace std; //finding the parity of given number bool getParity(unsigned int n) {    bool parity = 0;    while (n){       parity = !parity;       n = n & (n - 1);    }    return parity; } int main() {    unsigned int n = 7;    cout

Insert the string at the beginning of all items in a list in Python

Mohd Mohtashim
Updated on 16-May-2020 10:50:38

317 Views

In this post we need to enter the string at the beginning of all items in a list. For ex: We're given string = "Tutorials_Point" and List contains multiple element such as "1", "2" etc. So in this we need to add Tutorials_Point in front of "1", "2" and so on.ExampleAproach 1 Live Demosample_list = [1, 2, 3] print(['Tutorials_Point{0}'.format(i) for i in sample_list])Output//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']Approach 2 Live Demosample_list = [1, 2, 3] sample_str = 'Tutorials_Point' sample_str += '{0}' sample_list = ((map(sample_str.format, sample_list))) print(sample_list)Output//['Tutorials_Point1', 'Tutorials_Point2', 'Tutorials_Point3']Read More

Python - int() function

Mohd Mohtashim
Updated on 16-May-2020 10:45:43

3K+ Views

Python int() function converts the specified value into an integer number.The int() function will returns an integer object constructed from a number or string let say x, or return 0 if no argum ents are specified.Syntaxint(value, base) int(x, base=10)value = A number or a string that can be converted into an integer numberbase = A number representing the number format. Default value − 10Example# int() for integers int(10) 10 int(20) 20 # int() for floating point numbers int(11.2) 11 int(9.9e5) 990000

Python - Insert list in another list

Mohd Mohtashim
Updated on 16-May-2020 10:39:54

333 Views

A list also the extend() method, which appends items from the list you pass as an argument. extend() − Python list method extend() appends the contents of seq to list. You can read more about it here "https://www.tutorialspoint.com/python/list_append.htm"Now let us see hands onExample Live Demo#append first_list = [1, 2, 3, 4, 5] second_list = [6, 7, 8, 9, 10] first_list.append(second_list) # print result using append print("The list pattern using append is : " + str(first_list)) #extend third_list_ = [11, 12, 13, 14, 15] fourth_list = [16, 17, 18, 19, 20] third_list_.extend(fourth_list) print("The list pattern using extend is : " + str(third_list_))OutputThe ... Read More

Python - Increasing alternate element pattern in list

Mohd Mohtashim
Updated on 16-May-2020 10:37:27

170 Views

In this we are going to use List Comprehension with enumerate() Python provides compact syntax for deriving one list from another. These expressions are called list comprehensions.List comprehensions are one of the most powerful tools in Python. Python’s list comprehension is an example of the language’s support for functional programming concepts. You can read more about it here "www.tutorialspoint.com/python-list-comprehension" The enumerate() method adds counter to the iterable. You can read more about enumerate here " www.tutorialspoint.com/enumerate-in-python"Example Live Demo# declare list of integers my_list = [1, 2, 3] # printing the value print("Printing my_list list : " + str(my_list)) response = [value ... Read More

Advertisements