- 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
Print a character n times without using loop, recursion or goto in C++
In this section we will see how to print a character n times without using loops and recursion in C++. We can solve this problem by using string class constructors. There is a constructor where we are taking the character that will be printed multiple times, and the number of times it will be printed.
Example Code
#include <iostream> using namespace std; void print_char_n_times(char my_char, int count) { cout << string(count, my_char) << endl; } int main() { //print character B 10 times print_char_n_times('B', 10); //print character x 30 times print_char_n_times('x', 30); }
Output
BBBBBBBBBB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Related Articles
- Print a number 100 times without using loop, recursion and macro expansion in C
- Print 1 to 100 in C++, without loop and recursion
- How to print a name multiple times without loop statement using C language?
- Write a C program to print ‘ABCD’ repeatedly without using loop, recursion and any control structure
- Print a pattern without using any loop in C++
- Print m multiplies of n without using any loop in Python.
- Print first m multiples of n without using any loop in Python
- Printing all subsets of {1,2,3,…n} without using array or loop in C program
- Print root to leaf paths without using recursion in C++ Programming.
- Program to print root to leaf paths without using recursion using C++
- C program to print number series without using any loop
- Print Number series without using any loop in Python Program
- Print ancestors of a given binary tree node without recursion in C++
- Preorder Traversal of N-ary Tree Without Recursion in C++
- How will you print numbers from 1 to 100 without using loop in C?

Advertisements