+ 9
Make design using nested loops 1 121 12321 1234321 123454321 12345654321
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;
}
+ 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;
}
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.
0
@Stefan, how different is C++ 11/14/17 from Turbo C++?
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.
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?
0
if we would ake the same designe with phyton ,what should we do?
- 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
- 1
in int main statement if we use void main then return statement is required...?
- 3
h
- 4
andreykot1228