- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to concatenate a string given number of times?
Here we will see how we can concatenate a string n number of times. The value of n is given by the user. This problem is very simple. In C++ we can use + operator for concatenation. Please go through the code to get the idea.
Algorithm
concatStrNTimes(str, n)
begin res := empty string for i in range 1 to n, do res := concatenate res and res done return res end
Example
#include<iostream> using namespace std; main() { string myStr, res = ""; int n; cout << "Enter String: "; cin >> myStr; cout << "Enter number of times it will be concatenated: "; cin >> n; for(int i= 0; i < n; i++) { res += myStr; } cout << "Result: " << res; }
Output
Enter String: Hello Enter number of times it will be concatenated: 5 Result: HelloHelloHelloHelloHello
- Related Articles
- Concatenate a string given number of times in C++ programming
- C++ Program to Find the Number of Permutations of a Given String
- Java Program to Concatenate String.
- Java Program to concatenate a String and Integers
- Java Program to concatenate Integers and a String
- How to return a string repeated N number of times in C#?
- C/C++ Program to Find the Number Occurring Odd Number of Times?
- C program to calculate power of a given number
- C Program to print all permutations of a given string
- C++ code to count number of times stones can be given
- C Program to convert a number to a string
- Python program to count number of vowels using set in a given string
- C++ program to perform unique factorization of a Given Number
- C++ Program to Sum the digits of a given number
- Python program to check if a given string is number Palindrome

Advertisements