Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- n=5
- filas = n-1
- 123456789 12345
- 1 ***** 1***** n
- 2 * * 2* * 2
- 3 * * 3* * 2
- 4 * * 4* * 2
- 5* * 5* * 2
- 6 * * 6* * 2
- 7 * * 7* * 2
- 8 * * 8* * 2
- 9 ***** 9***** n
- */
- #include <iostream>
- #include <conio.h>
- using namespace std;
- void ParteSuperior (int n){
- for (int i=0; i<n-1;i++){
- for (int j=1; j<=n;j++){
- for (int x=1; x<n-i; x++){
- if (j==1){
- cout <<" ";}
- }
- if (n<10)
- if (i==0 || j==1 ||j==n){
- cout<<n;}
- else {cout << " ";}
- else
- if (i==0 || j==1 ||j==n){
- cout<<n;}
- else {cout << " ";}
- }
- cout << endl;
- }
- }
- void ParteCentral (int n){
- for (int i=1; i<=n;i++){
- if (n<10)
- if (i==1 ||i==n)
- cout << n;
- else
- cout << " ";
- else
- if (i==1 ||i==n)
- cout << n;
- else
- cout << " ";
- }cout << endl;
- }
- void ParteInferior (int n){
- for (int i=0;i<n-1;i++){
- for (int j=1; j<=n;j++){
- for (int x=n; x> n-i-1;x--){
- if (j==1){
- cout <<" ";}
- }
- if (n<10)
- if (i==n-2 || j==1 ||j==n){
- cout << n;}
- else
- cout << " ";
- else
- if (i==n-2 || j==1 ||j==n){
- cout << n;}
- else
- cout << " ";
- }
- cout << endl;
- }
- }
- int main (){
- int n;
- do {cout << "Intruduce el valor de n: "; cin >> n;}
- while (n<0 ||n>15);
- ParteSuperior(n);
- ParteCentral(n);
- ParteInferior(n);
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment