Created
November 23, 2014 09:57
-
-
Save sajadshokri/315614aa5476982d6620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
** numbers | |
** 1 | |
** 121 | |
** 12321 | |
** 121 | |
** 1 | |
*/ | |
#include <iostream> | |
#define hello "Hello \n" | |
#define msg "please enter one digit :" | |
#define error "is more than one digit \n" | |
void printNumbers(int n ,int i){ | |
//spaces | |
for(int j = n-i; j>=0; j--){ | |
std::cout <<" "; | |
} | |
//numbers ascending | |
for(int k = 1; k<=i ; k++){ | |
std::cout <<k; | |
} | |
//numbers descending | |
for(int l = i-1 ; l>=1 ; l--){ | |
std::cout << l; | |
} | |
std::cout << "\n"; | |
} | |
int main(){ | |
std::cout << hello << msg ; | |
int n = 5; | |
std::cin >>n; | |
if(n>=10){ | |
std::cerr << n << error; | |
return 1; | |
} | |
//first part | |
for(int i = 1; i<=n ; i++){ | |
printNumbers(n,i); | |
} | |
//second part | |
for(int i = n-1; i>=1 ; i--){ | |
printNumbers(n,i); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment