+ 4

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

Plz i need help i'm beginner ☺️

20th Oct 2021, 9:41 AM
Mohamed Elamin
Mohamed Elamin - avatar
19 ответов
+ 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; }
21st Oct 2021, 2:56 PM
MJARAB
MJARAB - avatar
+ 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; }
21st Oct 2021, 9:13 PM
Coding Cat
Coding Cat - avatar
+ 2
I will try to write code now
20th Oct 2021, 10:04 AM
Mohamed Elamin
Mohamed Elamin - avatar
+ 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
20th Oct 2021, 9:54 AM
Atul [Inactive]
+ 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
21st Oct 2021, 8:51 AM
sree harsha
sree harsha - avatar
+ 1
Mohamed Elamin Please check and kindly let me know If any problem
21st Oct 2021, 10:01 AM
sree harsha
sree harsha - avatar
+ 1
Thanks for you 💙👍
21st Oct 2021, 8:26 PM
Mohamed Elamin
Mohamed Elamin - avatar
+ 1
#include<stdio.h> printf("%d",1); printf("%d",12); printf("%d",123); printf("%d",1234); printf("%d",12345); Simple way - hard-coding 🌞
21st Oct 2021, 9:25 PM
Sanjay Kamath
Sanjay Kamath - avatar
0
Today is the first lecture in the loop (if) can i coding it just by if loop?
20th Oct 2021, 10:03 AM
Mohamed Elamin
Mohamed Elamin - avatar
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
21st Oct 2021, 5:23 AM
sree harsha
sree harsha - avatar
0
{ printf(”%d “,j); printf(””); } This 👆How it in c++??
21st Oct 2021, 8:42 AM
Mohamed Elamin
Mohamed Elamin - avatar
0
Martin Taylor It will execute in Linux compiler also
21st Oct 2021, 10:45 AM
sree harsha
sree harsha - avatar
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"; } }
21st Oct 2021, 8:25 PM
Mohamed Elamin
Mohamed Elamin - avatar
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; } }
22nd Oct 2021, 5:01 AM
Pranjal Pagar
Pranjal Pagar - avatar
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
22nd Oct 2021, 6:59 AM
sree harsha
sree harsha - avatar
0
#include<stream>
23rd Oct 2021, 5:49 PM
Sagar Panigrahi
Sagar Panigrahi - avatar
- 1
Oneliner 😉 for i in ("1","12","123","1234","12345"): print(i)
21st Oct 2021, 7:06 PM
Coding Cat
Coding Cat - avatar
- 1
printf("%d",1); printf("%d",1) printf("%d",1) printf("%d",1) printf("%d",1)
21st Oct 2021, 9:13 PM
Sanjay Kamath
Sanjay Kamath - avatar
- 5
Idk😁
21st Oct 2021, 7:37 AM
Arthur Zzekron 8