+ 9

Make design using nested loops 1 121 12321 1234321 123454321 12345654321

1st Oct 2016, 10:26 AM
Soutik
Soutik - avatar
11 ответов
+ 24
#include <iostream> using namespace std; int main() { int lim = 1; for(int i=1; i<=6; ++i) { for(int i=1; i<=(lim-1); ++i) { cout << i; } for (int i=0; i<lim; ++i) { cout << (lim-i); } cout << endl; lim = lim+1; } return 0; }
1st Oct 2016, 8:06 PM
Mohammed Maaz
Mohammed Maaz - avatar
+ 7
Similar to a previous answer, only spaces added to look more like what @Soutik asked #include <iostream> using namespace std; int main() { int print_limit = 6; /*printing up to number 6 */ for(int line_count=1; line_count <=print_limit ;line_count++) /*print upto 6 lines (print_limit )*/ { for(int space=1; space <=(print_limit - line_count +1); space++ ) /*print enough space to justify numbers to the centre*/ { cout << " "; } int print_num =1; while (print_num<line_count)/* print 1 to line count */ { cout << print_num ; print_num +=1; } while (print_num >=1) { cout << print_num ; print_num -=1; } cout << endl; } return 0; }
31st Oct 2016, 7:55 AM
Bejoy John
Bejoy John - avatar
0
@Umesh: Turbo C++ is obsolete as its product line has been discontinued in 2005 or 2006. In no modern implementation of C++ do the standard library headers still have the ".h" suffix. I'm not sure if it even complies to the C++03 standard. Nowadays C++11 and C++14 have significance, and soon the C++17 standard will be published. Nevertheless, Turbo C++ is still something you can learn but you will have to put in extra effort after learning to become a usable C++ programmer. Anyways, pls use one of the free more modern C++ alternatives to learn.
6th Nov 2016, 10:03 AM
Stefan
Stefan - avatar
0
@Stefan, how different is C++ 11/14/17 from Turbo C++?
6th Nov 2016, 10:43 AM
Bejoy John
Bejoy John - avatar
0
@Umesh: Turbo C++ does for sure not have any of the modern concepts like lambda functions, auto type deduction, move semantics etc. Also, its standard library is obsolete, e.g. unique and shared pointers, template handling etc. are missing. So maybe to compare it in a more understandable domain: it's like the difference between bicycle and motorbike.
6th Nov 2016, 11:23 AM
Stefan
Stefan - avatar
0
help me pls to understand, in these codes where is written, that the numbers draw a pyramid? in the loops where are the spaces?
13th Nov 2016, 9:51 PM
Benedek Máté Tóth
Benedek Máté Tóth - avatar
0
if we would ake the same designe with phyton ,what should we do?
11th Feb 2018, 6:14 PM
ayoub ayoub
- 1
is it turbo c++ is good for learning, but there is different, turbo have iostream.h and conio.h, while on net it's not shows
5th Oct 2016, 2:06 AM
umesh shetty
umesh shetty - avatar
- 1
in int main statement if we use void main then return statement is required...?
7th Oct 2016, 6:23 AM
dibs
dibs - avatar
- 3
h
11th Nov 2016, 1:39 AM
李坤和
李坤和 - avatar
- 4
andreykot1228
6th Nov 2016, 3:41 PM
Andrey
Andrey - avatar