Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 34 of 44

Program to print last N lines in c++

Ayush Gupta
Ayush Gupta
Updated on 02-Jan-2020 470 Views

In this tutorial, we will be discussing a program to print the last N lines.For this, we will be provided with a string that consists of the new line character to denote the start of the next line and the number of lines to be printed from the last. Our task is to start from the last and print all the N lines counting from the last.Example#include using namespace std; #define DELIM '' //printing the last N lines void print_last_lines(char *str, int n){    if (n

Read More

Program to print Kite Pattern in C++

Ayush Gupta
Ayush Gupta
Updated on 02-Jan-2020 1K+ Views

In this tutorial, we will be discussing a program to print the given Kite pattern.For this, we will be taking the input as N=5. Our task is to print the given Kite structure with the overall height of 2N+1 = 5. This includes 9 lines for the upper diamond structure and 2 for the lower incomplete diamond structure.Example Live Demo#include #include using namespace std; int main(){    int i, j, k, sp, space = 4;    char prt = '$';    //printing the upper half of the first diamond    for (i = 1; i = 1; sp--){          cout

Read More

Program to print Inverse Diamond pattern on C++

Ayush Gupta
Ayush Gupta
Updated on 02-Jan-2020 468 Views

In this tutorial, we will be discussing a program to print given inverse diamond pattern.For this, we will be provided with the value of N. Our task is to print an inverse the diamond pattern according to the height of 2N-1.Example Live Demo#include using namespace std; //printing the inverse diamond pattern void printDiamond(int n){    cout

Read More

Program to print Hut in C++

Ayush Gupta
Ayush Gupta
Updated on 02-Jan-2020 328 Views

In this tutorial, we will be discussing a program to print a Hut pattern.For this, we will be provided with the width of the hut to be printed (say N). Our task is to print a hut structure of the given width using stars and a gate inside the hut using line characters.Example Live Demo#include using namespace std; //printing the given hut structure int print_hut(int n){    int i, j, t;       if (n % 2 == 0) {          n++;       }       for (i = 0; i = n / 5)             || (j >= n / 5 && j < n - n / 5 && i == 0)             || (j == 0 && i >= n / 5)             || (j == t && i > n / 5)             || (i

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 321 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

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 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

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 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

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 541 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

Read More

Program to print a rectangle pattern in C++

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 931 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

Read More

Program to print 2D shapes in C++

Ayush Gupta
Ayush Gupta
Updated on 19-Dec-2019 490 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

Read More
Showing 331–340 of 433 articles
« Prev 1 32 33 34 35 36 44 Next »
Advertisements