how can we get the following output n c++
1
22
333
4444
55555
Hello @srinivas12,
What exactly are you having trouble with in this problem? Is it the output format, the algorithm itself, C++ syntax?
For your question to be more clearly answered please write a detailed and comprehensive question
Best regards,
Bruno
#include
#define n 5
using namespace std;
int main()
{
int i,j;
for(i=1;i<=n;++i)
{
for(j=1;j<=i;++j)
printf("%d",i);
printf(" ");
}
return 0;
}
This will do
3 Likes
#include
using namespace std;
int main(){
int n=4;
for (int i=1;i<=n;i++){
for(int k=1;k<=i;k++){
cout<<i;
}
cout<<"\n";
}
return 0;
}
This is similar to the above code but with more c++ approach.u may change ā\nā if u want the output in same line.
correct
using namespace std;
int main()
{
for (int i=1;i<6;i++)
{
for(int j=6;j>6-i;jā)
{
cout<<i<<" ";
}
}
return 0;
}