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
Programming Articles - Page 2218 of 3366
888 Views
In this tutorial, we will be discussing a program to print a given rectangular pattern.For this we will be given with the height and the breath of the rectangle. Our task is to print the rectangle with the given dimensions using the “@” character.Example Live Demo#include using namespace std; void print_rec(int h, int w){ for (int i=0; i
160 Views
Suppose we have a curve like y = x(A - x), we have to find the normal at a given point (x, y) on that curve. Here A is an integer number, x and y are also integers.To solve this, we have the check that the given point is on the curve or not, if so, then find the differentiation of that curve, so it will be −$$\frac{\text{d}y}{\text{d}x}=A-2x$$Then put x and y into the dy/dx, then find the normal using this equation −$$Y-y=-\lgroup\frac{\text{d}x}{\text{d}y}\rgroup*\lgroup X-x \rgroup$$Example Live Demo#include using namespace std; void getNormal(int A, int x, int y) { int differentiation ... Read More
628 Views
In this tutorial, we will be discussing a program to print a given pattern of numbers.Our task is to make use of looping structure in the code and print the given pattern − 1 232 34543 4567654 567898765Example Live Demo#include using namespace std; int main(){ int n = 5, i, j, num = 1, gap; gap = n - 1; for ( j = 1 ; j
159 Views
Here we will see how to find the nth term in Stern’s Diatomic series. The series is like 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, … This is also known as fusc function. This series can be defined as −𝑝(𝑛)=$p\lgroup\frac{n}{2}\rgroup$ 𝑤ℎ𝑒𝑛 𝑛 𝑖𝑠 𝑒𝑣𝑒𝑛𝑝(𝑛)=$p\lgroup\frac{n-1}{2}\rgroup+p\lgroup\frac{n+1}{2}\rgroup$ 𝑤ℎ𝑒𝑛 𝑛 𝑖𝑠 𝑜𝑑𝑑𝑝(0)=0 𝑎𝑛𝑑 𝑝(1)=1Here we will use the Dynamic programming approach to reduce the number of computations. After saving the base case for p(0) and p(1), we will iterate from index i = 2 to n, and compute p(i)Example Live Demo#include using namespace std; int findTerm(int ... Read More
185 Views
Suppose we have two integers N and D. We have to find a set of N integers, where the difference between their sum and product is the same as D. Suppose the N = 3, and D = 5, then the output will be 1, 2, 8. Here the sum is 1 + 2 + 8 = 11, and product is 1 * 2 * 8 = 16, the difference between 16 and 11 is 5.We have to solve this problem; we will use one tricky method. Here we will try to find N–2 number of 1s, one 2, and ... Read More
455 Views
In this tutorial, we will be discussing a program to print out 2D shapes.For this we will be provided with the various parameters required to make a shape such as radius, side length and side breadth, etc. And our task is to print a shape accordingly with no thickness.Example Live Demo#include using namespace std; void print_circle(int radius){ for (int i = 0; i
244 Views
Suppose we have three values, a, b and x. We have to find one multiple of x, that is nearest to ab. Suppose the numbers are x = 4, a = 3, b = 3, then the output will be 28, as this is nearest to 33 = 27The approach is simple; we have to follow these conditions −If b < 0, and a = 1, then ab turns out to be 1 and hence, the closest multiple of x becomes either 0 or x.If b < 0 and a > 1, then, ab, turns out to be less than ... Read More
320 Views
Suppose we have four integers a, b, c and k. We have to find the minimum positive value x, such that the following equation satisfies −𝑎𝑥2+𝑏𝑥+𝑐 ≥𝑘If a = 3, b = 4, c = 5 and k = 6, then output will be 1To solve this, we will use the bisection approach. The lower limit will be 0 since x has to be a minimum positive integer.Example Live Demo#include using namespace std; int getMinX(int a, int b, int c, int k) { int x = INT8_MAX; if (k
751 Views
Suppose we have an array of n elements called A. We have to find the minimum difference between any two elements in that array. Suppose the A = [30, 5, 20, 9], then the result will be 4. this is the minimum distance of elements 5 and 9.To solve this problem, we have to follow these steps −Sort the array in non-decreasing orderInitialize the difference as infiniteCompare all adjacent pairs in the sorted array and keep track of the minimum oneExample#include #include using namespace std; int getMinimumDifference(int a[], int n) { sort(a, a+n); int min_diff = INT_MAX; for (int i=0; i
216 Views
In this tutorial, we will be discussing a program to print ‘N’ alphabet using the number pattern from 1 to n.For this we will have to print the english alphabet N. Our task is to determine the size of the letter and print it back using the numbers from 1 to n.Example Live Demo#include using namespace std; //printing the letter N void print_N(int N){ int index, side_index, size; int Right = 1, Left = 1, Diagonal = 2; for (index = 0; index < N; index++) { cout