Â
In this, we are going to see for loop, the program is based on for loop which basically, prints the user input, for the number of times defined by the user.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i;
char a;
cout<<"Enter any character "<<endl;
cin>>a;
cout<<"Enter no of times the character should repeat"<<endl;
cin>>n;
for(i=0;i<=n-1;i++)
{
cout<<a<<endl;
}
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
int n,i;
char a;
cout<<"Enter any character "<<endl;
cin>>a;
cout<<"Enter no of times the character should repeat"<<endl;
cin>>n;
for(i=0;i<=n-1;i++)
{
cout<<a<<endl;
}
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP