Ayush Gupta

Ayush Gupta

433 Articles Published

Articles by Ayush Gupta

Page 34 of 44

Convert a number of length N such that it contains any one digit at least 'K' times in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 161 Views

In this tutorial, we will be discussing a program to convert a number of length N such that it contains any one digit at least ‘K’ times.For this we will be provided with a number of given length N. Our task is to convert the digits in the given number such that any one digit gets repeated at least ‘K’ times. Also, you have to calculate the cost of this operation which is the absolute difference between the two and finally print the minimum cost.Example#include using namespace std; //calculating the minimum value and final number int get_final(int n, int ...

Read More

Convert a sentence into its equivalent mobile numeric keypad sequence in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 761 Views

In this tutorial, we will be discussing a program to convert a sentence into its equivalent mobile numeric keypad sequence.For this we will be provided with a string of alphabetical characters. Our task is to print the numeric equivalent of the string i.e the numerical sequence of the keys to type that particular string.Example#include using namespace std; //computing the numerical sequence string calc_sequence(string arr[], string input){    string output = "";    //length of input string    int n = input.length();    for (int i=0; i

Read More

Convert a String into a square matrix grid of characters in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 439 Views

In this tutorial, we will be discussing a program to convert a string into a square matrix grid of characters.For this we will be provided with a string of characters. Our task is to print that particular string in the format of a matrix grid having a certain number of rows and columns.Example#include using namespace std; //converting the string in grid format void convert_grid(string str){    int l = str.length();    int k = 0, row, column;    row = floor(sqrt(l));    column = ceil(sqrt(l));    if (row * column < l)       row = column;   ...

Read More

Convert a string to hexadecimal ASCII values in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 2K+ Views

In this tutorial, we will be discussing a program to convert a string to hexadecimal ASCII values.For this we will be provided with a string of characters. Our task is to print that particular given string into its hexadecimal equivalent.Example#include #include //converting string to hexadecimal void convert_hexa(char* input, char* output){    int loop=0;    int i=0;    while(input[loop] != '\0'){       sprintf((char*)(output+i), "%02X", input[loop]);       loop+=1;       i+=2;    }    //marking the end of the string    output[i++] = '\0'; } int main(){    char ascii_str[] = "tutorials point";    int ...

Read More

Convert a tree to forest of even nodes in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 288 Views

In this tutorial, we will be discussing a program to convert a tree to a forest of even nodes.For this we will be provided with a binary tree of say N nodes. Our task is to calculate the maximum number of edges that can be removed to get forest of even nodes.Example#include #define N 12 using namespace std; //returning the number of nodes of subtree //having the root node int depth_search(vector tree[N], int visit[N], int *ans, int node){    int num = 0, temp = 0;    //marking nodes as visited    visit[node] = 1;    for (int i = ...

Read More

Convert all lowercase characters to uppercase whose ASCII value is co-prime with k in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 173 Views

In this tutorial, we will be discussing a program to convert all lowercase characters to uppercase whose ASCII value is co-prime with k.For this we will be provided with a string and an integer value k. Our task is to traverse through the given string and change to uppercase all those characters whose ASCII value is co-prime with the given integer k.Example#include using namespace std; //modifying the given string void convert_string(string s, int k){    int l = s.length();    for (int i = 0; i < l; i++) {       int ascii = (int)s[i];     ...

Read More

Program to print a rectangle pattern in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 944 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#include using namespace std; void print_rec(int h, int w){    for (int i=0; i

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 550 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#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 all substrings of a given string in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 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#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 the numbers divisible by 3 and 5 in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 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#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
Showing 331–340 of 433 articles
« Prev 1 32 33 34 35 36 44 Next »
Advertisements