Johnqc

Problema 3 de Parcial

May 24th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. /*
  2. n=5
  3. filas = n-1
  4. 123456789 12345
  5. 1 ***** 1***** n
  6. 2 * * 2* * 2
  7. 3 * * 3* * 2
  8. 4 * * 4* * 2
  9.  
  10.  
  11. 5* * 5* * 2
  12.  
  13.  
  14. 6 * * 6* * 2
  15. 7 * * 7* * 2
  16. 8 * * 8* * 2
  17. 9 ***** 9***** n
  18.  
  19. */
  20. #include <iostream>
  21. #include <conio.h>
  22. using namespace std;
  23.  
  24. void ParteSuperior (int n){
  25.  
  26. for (int i=0; i<n-1;i++){
  27. for (int j=1; j<=n;j++){
  28. for (int x=1; x<n-i; x++){
  29. if (j==1){
  30. cout <<" ";}
  31. }
  32. if (n<10)
  33. if (i==0 || j==1 ||j==n){
  34. cout<<n;}
  35. else {cout << " ";}
  36. else
  37. if (i==0 || j==1 ||j==n){
  38. cout<<n;}
  39. else {cout << " ";}
  40. }
  41. cout << endl;
  42. }
  43.  
  44. }
  45.  
  46. void ParteCentral (int n){
  47.  
  48. for (int i=1; i<=n;i++){
  49. if (n<10)
  50. if (i==1 ||i==n)
  51. cout << n;
  52. else
  53. cout << " ";
  54. else
  55. if (i==1 ||i==n)
  56. cout << n;
  57. else
  58. cout << " ";
  59.  
  60. }cout << endl;
  61. }
  62.  
  63. void ParteInferior (int n){
  64.  
  65. for (int i=0;i<n-1;i++){
  66. for (int j=1; j<=n;j++){
  67. for (int x=n; x> n-i-1;x--){
  68. if (j==1){
  69. cout <<" ";}
  70. }
  71. if (n<10)
  72. if (i==n-2 || j==1 ||j==n){
  73. cout << n;}
  74. else
  75. cout << " ";
  76. else
  77. if (i==n-2 || j==1 ||j==n){
  78. cout << n;}
  79. else
  80. cout << " ";
  81. }
  82. cout << endl;
  83. }
  84. }
  85.  
  86.  
  87. int main (){
  88. int n;
  89. do {cout << "Intruduce el valor de n: "; cin >> n;}
  90. while (n<0 ||n>15);
  91. ParteSuperior(n);
  92. ParteCentral(n);
  93. ParteInferior(n);
  94.  
  95.  
  96. getch();
  97. return 0;
  98. }
Add Comment
Please, Sign In to add comment