Posted By

Desoxena on 01/26/11


Tagged

number pyramid


Versions (?)

number pyramid


 / Published in: C++
 

this small script will make a small triangle of numbers; script and example are below.

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int a=0, b=0, c=1, i;
  10. do{
  11. for (i=9;i!=0;i--) {
  12. string space (i,' ');
  13. cout << space;
  14. for (a=0;a<c;a++) {
  15. cout << a;
  16. }
  17. c++;
  18. for (b=a;b!=-1;b--) {
  19. cout << b;
  20. }
  21. cout << "\n";
  22. }
  23. }while (c != 10);
  24. system("pause");
  25. }
  26. // EXAMPLE:
  27. // 010
  28. // 01210
  29. // 0123210
  30. // 012343210
  31. // 01234543210
  32. // 0123456543210
  33. // 012345676543210
  34. // 01234567876543210
  35. //0123456789876543210

Report this snippet  

You need to login to post a comment.