Found 7197 Articles for C++

Program to print an inverse pyramid character pattern in C++

Ayush Gupta
Updated on 19-Dec-2019 10:50:43

276 Views

In this tutorial, we will be discussing a program to print an inverse pyramid character pattern.For this we will be provided with the number of rows containing in the inverted pyramid triangle. Our task is to print the alphabets in the given number of rows to develop the shape of an inverse pyramid.Example Live Demo#include using namespace std; //printing the inverse pyramid pattern void inv_pyramid(int n){    int i, j, num, gap;    for (i = n; i >= 1; i--) {       for (gap = n - 1; gap >= i; gap--) {          cout

Find Tangent at a given point on the curve in C++

Arnab Chakraborty
Updated on 19-Dec-2019 10:54:19

358 Views

Suppose we have a curve like y = x(A - x), we have to find the tangent 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 tangent using this equation −$$Y-y=-\lgroup\frac{\text{d}y}{\text{d}x}\rgroup*\lgroup X-x \rgroup$$Example Live Demo#include using namespace std; void getTangent(int A, int x, int y) {    int differentiation ... Read More

Find sum of sum of all sub-sequences in C++

Arnab Chakraborty
Updated on 19-Dec-2019 10:43:11

247 Views

Consider we have an array A with n elements. We have to find the total sum of the sum of all the subsets of the array. So if the array is like A = [5, 6, 8], then it will be like −SubsetSum5566885, 6116, 8145, 8135, 6, 819Total Sum76As the array has n elements, then we have a 2n number of subsets (including empty). If we observe it clearly, then we can find that each element occurs 2n-1 timesExample Live Demo#include #include using namespace std; int totalSum(int arr[], int n) {    int res = 0;    for (int i = ... Read More

Program to print all the numbers divisible by 3 and 5 in C++

Ayush Gupta
Updated on 19-Dec-2019 10:46:24

1K+ Views

In this tutorial, we will be discussing a program to print all the numbers divisible by 3 and 5 less than the given number.For this we will be given with a number say N. Our task is to print all the numbers less than N which are divisible by both 3 and 5.Example Live Demo#include using namespace std; //printing the numbers divisible by 3 and 5 void print_div(int N){    for (int num = 0; num < N; num++){       if (num % 3 == 0 && num % 5 == 0)       cout

Find sum of digits in factorial of a number in C++

Arnab Chakraborty
Updated on 19-Dec-2019 10:40:11

531 Views

Suppose, we have a number n, our task is to find the sum of digits in then!. Consider n = 5, then n! = 120. So the result will be 3.To solve this problem, we will create a vector to store factorial digits and initialize it with 1. Then multiply 1 to n one by one to the vector. Now sum all the elements in the vector and return the sumExample Live Demo#include #include using namespace std; void vectorMultiply(vector &v, int x) {    int carry = 0, res;    int size = v.size();    for (int i = 0 ; ... Read More

Program to print all substrings of a given string in C++

Ayush Gupta
Updated on 19-Dec-2019 10:38:57

3K+ Views

In this tutorial, we will be discussing a program to print all the substring of a given string.For this we will be given with a string or an array of characters. Our task is to print all the substrings of that particular string.Example Live Demo#include using namespace std; //printing all the substrings void print_substr(char str[], int n){    for (int len = 1; len

Find reminder of array multiplication divided by n in C++

Arnab Chakraborty
Updated on 19-Dec-2019 10:37:48

141 Views

Suppose we have an array of n elements called A. We have to print the remainder after multiply all the numbers divided by n. Suppose A = [100, 10, 5, 25, 35, 14], and n = 11. The output is 9. So the value of 100 * 10 * 5 * 25 * 35 * 14 mod 11 = 9.First, we have to take the remainder of each number, then multiply the remainder with the current result. After multiplication, again take the remainder to avoid overflow.Example Live Demo#include #include using namespace std; int getRemainder(int a[], int size, int n) {    int mul = 1;    for(int i = 0; i

Program to print all palindromes in a given range in C++

Ayush Gupta
Updated on 19-Dec-2019 10:36:25

483 Views

In this tutorial, we will be discussing a program to print all palindromes in a given range.For this we will be given the mathematical range in which the palindromes are to be found. Our task is to find all the palindromes in that range and print it back.Example Live Demo#include using namespace std; //checking if the number is a palindrome int is_palin(int n){    int rev = 0;    for (int i = n; i > 0; i /= 10)    rev = rev*10 + i%10;    return (n==rev); } void countPal(int min, int max){    for (int i = min; i

Program to print a rectangle pattern in C++

Ayush Gupta
Updated on 19-Dec-2019 10:33:32

874 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

Find normal at a given point on the curve in C++

Arnab Chakraborty
Updated on 19-Dec-2019 10:34:57

149 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

Advertisements