Holey_yan

20140409_KUAS_VisualC++_Classwork_0409_Question_2_Answer

Apr 12th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. /***********************************************/
  2. /** 20140409 Classwork_0409 Question 2 Answer **/
  3. /** Maker  : Yan                              **/
  4. /** E-Mail : [email protected]            **/
  5. /** Date   : 2014/04/09 pm.10:36              **/
  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.     for(int i = 1; i <= input * 2 - 1; i++)
  17.     {
  18.         if(i <= input)
  19.         {
  20.             for(int j = 1; j <= input - i; j++)
  21.             {
  22.                 printf(" ");
  23.             }
  24.             for(int j = 1; j <= i; j++)
  25.             {
  26.                 printf("* ");
  27.             }
  28.             printf("\n");
  29.         }
  30.         else if(i > input)
  31.         {
  32.             for(int j = 1; j <= i - input; j++)
  33.             {
  34.                 printf(" ");
  35.             }
  36.             for(int j = 1; j <= input * 2 - i; j++)
  37.             {
  38.                 printf("* ");
  39.             }
  40.             printf("\n");
  41.         }
  42.     }
  43.     system("pause");
  44. }
Advertisement
Add Comment
Please, Sign In to add comment