Found 26504 Articles for Server Side Programming

C++ program to make student type data and display in proper format

Arnab Chakraborty
Updated on 07-Oct-2021 07:39:53

212 Views

Suppose we have provided the first name, last name, age and class of a student in different lines. We shall have to write a program using structs in C++ to read them all and show in this format (age, first_name, last_name, class). The age and class will be of type integer, and first_name and last_name are of time string.So, if the input is likepriyam kundu 16 10then the output will be (16, priyam, kundu, 10)To solve this, we will follow these steps −define a structure with first_name, last_name of type string and age, cl of type integerread each line and ... Read More

C++ program to get length of strings, perform concatenation and swap characters

Arnab Chakraborty
Updated on 07-Oct-2021 07:37:09

359 Views

Suppose we have two strings s and t, we shall have to find output in three lines, the first line contains lengths of s and t separated by spaces, the second line is holding concatenation of s and t, and third line contains s and t separated by space but their first characters are swapped.So, if the input is like s = "hello", t = "programmer", then the output will be5 10 helloprogrammer pello hrogrammerTo solve this, we will follow these steps −display length of s then print one space and length of tdisplay s + ttemp := s[0]s[0] := ... Read More

C++ Program to take out integer from comma separated string

Arnab Chakraborty
Updated on 07-Oct-2021 07:35:03

4K+ Views

Suppose we have a string where we have few integers which are separated by comma. We shall have to separate them out and display each integer in different line. To do this we shall use stringstream (under sstream library) in C++. This is one string based stream class present in C++. We can use extraction operator () to insert something and str() functions to set contents of underlying string device object.So, if the input is like s = "56, 9, 85, 256, 47", then the output will be56 9 85 256 47To solve this, we will follow these steps −Define ... Read More

C++ program to reverse an array elements (in place)

Arnab Chakraborty
Updated on 07-Oct-2021 07:32:30

22K+ Views

Suppose we have an array with n different elements. We shall have to reverse the elements present in the array and display them. (Do not print them in reverse order, reverse elements in place).So, if the input is like n = 9 arr = [2, 5, 6, 4, 7, 8, 3, 6, 4], then the output will be [4, 6, 3, 8, 7, 4, 6, 5, 2]To solve this, we will follow these steps −for initialize i := 0, when i < quotient of n/2, update (increase i by 1), do:temp := arr[i]arr[i] := arr[n - i - 1]arr[n - ... Read More

C++ program to find addition and subtraction using function call by address

Arnab Chakraborty
Updated on 07-Oct-2021 07:29:43

2K+ Views

Suppose we have two numbers a and b. We shall have to define a function that can calculate (a + b) and (a - b) both. But using a function in C++, we can return at most one value. To find more than one output, we can use output parameters into function arguments using pointers, and call that function using addresses of those variables. Here in this problem we shall update a with a+b and b with a-b. When we call the function we shall have to pass the address of these two variables.So, if the input is like a ... Read More

C++ program to find greatest among four input integers

Arnab Chakraborty
Updated on 07-Oct-2021 07:27:19

6K+ Views

Suppose we have four integers a, b, c and d. We shall have to find the greatest number among them by making our own function. So we shall create one max() function that takes two numbers as input and finds the maximum, then using them we shall find maximum of all four numbers.So, if the input is like a = 75, b = 18, c = 25, d = 98, then the output will be 98.To solve this, we will follow these steps −define a function max(), this will take x and yreturn maximum of x and ytake four numbers ... Read More

Program to distribute repeating integers in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:52:26

189 Views

Suppose we have an array nums, there are at most 50 unique values. We also have another array called quantity, where quantity[i] denotes the amount of values the ith customer ordered.We have to check whether it is possible to distribute nums such thatThe ith customer gets exactly quantity[i] items, The value that the ith customer gets are all equal, andAll customers are satisfied.So, if the input is like nums = [5, 1, 2, 2, 3, 4, 4, 3, 3] quantity = [2, 2, 3], then the output will be True because two customer wants two elements each, so they can ... Read More

C++ program to convert all digits from the given range into words

Arnab Chakraborty
Updated on 07-Oct-2021 07:24:41

424 Views

Suppose we have two digits a and b. We shall have to convert each digit into words and print them one by one. Printing digits into words means for a digit 5, it should print "Five".So, if the input is like a = 2, b = 6, then the output will beTwo Three Four Five SixTo solve this, we will follow these steps −if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as 1, then:return ("One")otherwise when d is same as 2, ... Read More

Program to find number of ways to form a target string given a dictionary in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:33:32

748 Views

Suppose we have a list of string called words, where all elements are of same length. We also have a string called target. We have to generate target using the given words under the following rules −We should generate target from left to right.To get the ith character (0-indexed) of target, we can select the kth character of the jth string in words when target[i] is same as words[j][k].Once we use the kth character of the jth string of words, we cannot use the xth character of any string in words where x at index 0 ("qppq"), at index ... Read More

Program to find minimum one bit operations to make integers zero in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:20:00

316 Views

Suppose we have a number n, we have to transform it into 0 using the following operations any number of times −Select the rightmost bit in the binary representation of n.Change the ith bit in the binary representation of n when the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.So finally we have to find the minimum number of operations required to transform n into 0.So, if the input is like n = 6, then the output will be 4 because initially 6 = "110", then convert it to "010" by second ... Read More

Advertisements