Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1771 of 2650
870 Views
In this article, we are given two numbers n and k representing a series. Our task is to create a program in C++ that finds the sum of the sequence given below: The input cycle is the process of adding up all the numbers in the given sequence to get a single output. The process of recursion is frequently used in mathematics and may be implemented with sequences namely the arithmetic ones ( each term is acquired by adding a constant difference between the previous one) and the geometric sequence ( where each term is multiplied by a constant ratio with the former term ... Read More
411 Views
In this tutorial, we will be discussing a program to find sum of first n natural numbers.For this we will be provided with an integer n. Our task is to add up, find the sum of the first n natural numbers and print it out.Example Live Demo#include using namespace std; //returning sum of first n natural numbers int findSum(int n) { int sum = 0; for (int x=1; x
1K+ Views
In this problem, we are given an array arr[] of n integer values. Our task is to create a Program to find sum of elements in a given array in C++.Program Description − For the given array, we will add up all elements and return the sum.Let’s take an example to understand the problemInputarr[] = {3, 1, 7, 2, 9, 10}Output32ExplanationSum = 3 + 1 + 7 + 2 + 9 + 10 = 32Solution ApproachTo find the sum of elements of the array, we will traverse the array and extract each element of the array and add them to ... Read More
618 Views
In this problem, we are given two numbers a and n. Our task is to create a program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n! in C++.Problem description − The problem is to find the sum of the given series using the given values of a and n. The series is a special series in which each term is the multiple of the last term with a/i, i -> 1 to n.Let’s take an example to understand the problemInputa = 3, n = 4Output15.375Explanationsum of series is(3^1)/1! + (3^2)/2! + (3^3)/3! + ... Read More
319 Views
In this problem, we are given two values x and n that corresponds to the given series. Our task is to create a program to find sum of 1 + x/2! + x^2/3! +…+x^n/(n+1)! in C++.Problem description − we need to find the sum of series based on the given values of x and n. In the series, every other term differs from the previous term by x/i for ith term.Let’s take an example to understand the problemInputx = 6, n = 4Output29.8ExplanationThe sum of the series is1 + 6/2 + 36/6 + 216/24 + 1296/120 = 29.8Solution ApproachTo find ... Read More
171 Views
In this problem, we are given a number n. Our task is to create a program to find Star number in C++.Star Number is a special number that represents a centered hexagram (sixpoint star).Some start numbers are 1, 13, 37, 73, 121.Let’s take an example to understand the problemInputn = 5Output121Solution ApproachTo find the nth star number we will use the formula.Let’s see the general formula for the star number.n = 2 -> 13 = 12 + 1 = 6(2) + 1 n = 3 -> 37 = 36 + 1 = 6(6) + 1 n = 4 -> 73 ... Read More
239 Views
Suppose we have a data stream input of integers, these are like a1, a2, ..., an, ..., we have to summarize the numbers seen so far as a list of disjoint intervals. For example, suppose the input integers are 1, 3, 8, 2, 7, ..., then the summary will be −[1, 1][1, 1], [3, 3][1, 1], [3, 3], [8, 8][1, 3], [8, 8][1, 3], [7, 8].To solve this, we will follow these steps −Make a set called numsin the initializer, set low := -inf and high := infFrom the addNum method that takes num as input, insert num into the ... Read More
290 Views
Suppose we have an array x of n numbers. We start at point (0, 0) and moves x[0] units to the north direction, then x[1] units to the west direction, x[2] units to the south direction , x[3] units to the east direction and so on. In other words, after each move our direction changes counter-clockwise. We have to devise an one-pass algorithm with O(1) extra space to determine whether our path crosses itself, or not.So if the array is like − [3, 4, 2, 5]Answer will be true.To solve this, we will follow these steps −insert 0 at the ... Read More
383 Views
Suppose we have an array nums and one number. We can add elements in the array, such that any number in range [1, n] (both are inclusive) can be formed by the sum of some elements in the array. We have to find the minimum number of required patches. So when the array is like [1, 4] and given number is n = 7, then output will be 1, as initially the nums are [1], [4] and [1, 4] = 5, now if we add 2 into array, then the nums will be [1], [2], [4], [1, 2], [1, 4], ... Read More
201 Views
Suppose we have a string consisting of only lowercase letters. We have to remove all duplicate letters such that all letters only occur once. And we have to display the result in the smallest lexicographic sequence. So if the input is like “abccb”, then the result will be “abc”To solve this, we will follow these steps −ans := one empty stringDefine one stack stDefine an array onStack of size 26Define one map mn := size of sfor initializing i := 0, when i < n, increase i by 1 do −increase m[s[i]] by 1for initializing i := 0, when i ... Read More