.. How to write code to print : 1 12 123 1234 12345 | Sololearn: Learn to code for FREE!

+4

.. How to write code to print : 1 12 123 1234 12345

Plz i need help i'm beginner ☺️

c++

10/20/2021 9:41:01 AM

Mohamed Elamin

24 Answers

New Answer

+6

#include<iostream> using name space std; int main() { int n; cin>>n; // n==5 for(int i=1;i<n;i++) { for(int j=1;j<=i;j++) { cout<<j<<" "; } cout<<endl; } return 0; }

+7

Jay Mathews, why on earth would you need two nested loops? I can do it in a single loop. Just append a digit to the output string each time through the loop.

+5

You start by completing more than 2% of the C++ course. Conditionals and loops are covered in lessons 12 to 21 in the C++ course. Sololearn is neither a code writing service nor an assignment completion service. Please show your attempt rather than just asking for code.

+4

C++ with single loop: #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string s = ""; for (int x=1; x<=5; x++) { stringstream ss; ss << s << x; ss >> s; cout << s << endl; } return 0; }

+2

I will try to write code now

+1

You need two nested for loops.

+1

Do you know the concept of loops or pattern ? If no then, If you see the number of columns=number of rows And make a counter which increases every column and turns 0 when a row is finished

+1

Mohamed Elamin, the if statement is a conditional statement not a loop statement. The for, while, and do-while statements are loop statements.

+1

Mohamed Elamin Try to understand the logic Even programming language is changed logic remain the same right In C printf In CPP cout In JAVA System.out.println(””); In PYTHON print() Method name is changing but logic will be same

+1

sree harsha, you must be another Turbo C refugee. That code won't compile in any standards compliant compiler. Please don't post Turbo C dross. It merely confuses people not still living in the 1980s. I would image that the majority of Sololearn users weren't even born then.

+1

Mohamed Elamin Please check and kindly let me know If any problem

+1

Thanks for you 💙👍

+1

#include<stdio.h> printf("%d",1); printf("%d",12); printf("%d",123); printf("%d",1234); printf("%d",12345); Simple way - hard-coding 🌞

0

Today is the first lecture in the loop (if) can i coding it just by if loop?

0

#include<iostream.h> #include<conio.h> int main() { int i, j; clrscr(); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) cout<<j<<” “; cout<<endl; } getch(); return 0; } The above code will generate your requested output

0

{ printf(”%d “,j); printf(””); } This 👆How it in c++??

0

Martin Taylor It will execute in Linux compiler also

0

#include <iostream> using namespace std; int main() { int i,j; for (i=1;i<=5;i++) { for(j=1;j<=i;j++) cout<<j; cout<<"\n"; } }

0

#include <iostream> using namespace std; int main() { int n; cout<<"Enter value of n"<<endl; cin>>n; int i=1; while(i<=n) { int j=1; while (j<=i) { cout<<j; j=j+1; } cout<<endl; i=i+1; } }

0

Martin Taylor You mean Loops Arrays Strings Functions Pointers Way of programming and syntax has everything changed after turboc compiler Kindly let me know