Holey_yan

20140409_KUAS_VisualC++_Classwork_0409_Question_3_Answer

Apr 12th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. /***********************************************/
  2. /** 20140409 Classwork_0409 Question 3 Answer **/
  3. /** Maker  : Yan                              **/
  4. /** E-Mail : [email protected]            **/
  5. /** Date   : 2014/04/09 pm.10:45              **/
  6. /***********************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. void main()
  12. {
  13.     printf("Enter a number: ");
  14.     int input = 0;
  15.     scanf("%d", &input);
  16.     if(input <= 9)
  17.     {
  18.         for(int i = 1; i <= input; i++)
  19.         {
  20.             if(i != input)
  21.             {
  22.                 for(int j = 1; j <= input - i; j++)
  23.                 {
  24.                     printf(" ");
  25.                 }
  26.                 if(i != 1)
  27.                 {
  28.                     printf("%d", i);
  29.                     printf(" ");
  30.                 }
  31.                 for(int j = 3; j <= i; j++)
  32.                 {
  33.                     printf("  ");
  34.                 }
  35.                 printf("%d\n", i);
  36.             }
  37.             else if(i == input)
  38.             {
  39.                 for(int j = 1; j <= input; j++)
  40.                 {
  41.                     printf("%d ", i);
  42.                 }
  43.                 printf("\n");
  44.             }
  45.         }
  46.     }
  47.     system("pause");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment