c ++ print solid diamonds, open triangles, cross star, open squares, solid parallelogram

Today turn data when accidentally discovered a file is new to programming when using c ++ to write a program I call "graphics printer", think of all the graphics are printed, and later discovered that in fact each graphic the code is an idea, I do not want to repeat the work. Today turn to put it down to be a memorial.

#include<stdio.h>
#include<stdlib.h>

// function selection interface
void menu ();

// declared
void Statement ();

// print solid diamond
int Solid_diamond ();

// open triangle print
int Hollow_triangle ();

// print cruciform
int Cross ();

// print hollow square
int Hollow_square ();

// print solid parallelogram
int Solid_parallelogram ();

//主函数
main(void)
{
  int n;
  printf("\t\t\t欢迎体验1.0版本图形打印机\n\n\n");
  while(1)
  {
    menu();
    printf("Please select a funcyion:");
    scanf("%d",&n);
    switch(n)
    {
      case 1:Statement();break;
      case 2:Solid_diamond();break;
      case 3:Hollow_triangle();break;
      case 4:Cross();break;
      case 5:Hollow_square();break;
      case 6:Solid_parallelogram();break;
      case 0:exit(0);break;
    }
    if(n<0||n>6)
      printf("\t\t\t---Input Error!---\n\n\n");
  }
}


// declare interface
void the Statement ()
{
  the printf ( "\ n-\ n-\ n-");
  the printf ( "The interface. 1 --- Because IS TOO Small, SO, Please Enter A Number 20 is less Within last \ n-");
  the printf ( "(because the interface is too small, so input 20 is smaller than the number in order to observe) \ n-");
  the printf ( "current Version of the 2 --- only the Supports the Dictionary Dictionary English Language \ n-");
  the printf ( "(as the current level limited, so only supports English mode) \ the n-");
  printf (" 3 --- the find the If you problem, Please Me in Time Business Card, tkank you \ the n-");
  printf (" found the problem (if you are in the course of Please contact me, thank you) \ the n-\ the n-\ the n-");
}

 

// menu interface
void MENU ()
{
  the printf ( "\ n-\ n-\ n-");
  the printf ( "\ T \ T \ T1 --- the Statement (declared) \ n-");
  the printf ( "\ T \ T \ t2 --- solid diamond (solid diamonds) \ n-");
  the printf (" \ T \ T \ --- hollow triangle T3 (open triangles) \ n-");
  the printf (" \ T \ T \ t4-- -Cross (cross) \ n-");
  the printf (" \ T \ T \ --- T5 Hollow_square (open squares) \ n-");
  the printf (" \ T \ T \ --- T6 Solid_parallelogram (solid parallelogram ) \ the n-");
  printf (" \ t \ t \ t0 --- program at The exit (exit the program) \ the n-\ the n-\ the n-");
  printf (" Important: "Support English Only" \ the n-\ the n-\ the n- ");
}

 

 

// solid diamond
int Solid_diamond ()
{
  int I, J, n-;
  char m;
  the printf ( "Please Enter The Order Number (Enter order):");
  Scanf ( "% D", & n-);
  fflush (stdin ); // Clear cache
  printf ( "Please enter the character (enter character):");
  Scanf ( "% C", & m);
  IF (n-<= 0)
  the printf ( "\ T \ T \ TInput Error ! \ n-");
  for (I =. 1; I <= n-; I ++)
  {
    for (J =. 1; J <= Ni; J ++)
    the printf (" ");
    for (J =. 1; J <= 2 * I-1; J ++)
    the printf ( "% C", m);
    the printf ( "\ n-");
  }
  / * first play the n-1 after the space by an asterisk, and then the space is gradually reduced, an asterisk 2 * 1 in the form of increased
  print only part of the space to the left and right spaces unprinted.
  The maximum print order * /
  for (I =. 1; I <= n--. 1;


    the printf ( "");
    for (J =. 1; J <2 * (Ni); J ++)
    the printf ( "% C", m);
    the printf ( "\ n-");
  }
  // modeled formula, reverse printing, just pay attention less than a first-order equation
}

 

// open triangle
int Hollow_triangle ()
{
  int I, J, n-;
  char m;
  the printf ( "Please Enter The Order Number (Enter order):");
  Scanf ( "% D", & n-);
  fflush (stdin ); // Clear cache
  printf ( "Please enter the character (enter character):");
  Scanf ( "% C", & m);
  IF (n-<= 0)
  the printf ( "\ T \ T \ TInput Error ! \ n-");
  for (I =. 1; I <n-+. 1; I ++)
  {
    for (J =. 1; J <2 * n-; J ++)
    {
    IF (J == n--I +. 1 || J = . 1-n-I + = || n-&& J == I == 2%. 1)
      the printf ( "% C", m);
    // J = I +. 1-n-symbol printed on the left; j = n + i-1 to the right of Print symbol; i = n && j% 2 == 1 asterisk print last layer
    the else
      the printf ( "");// In addition to the asterisks rest are all spaces
    }
    printf ( "\ the n-");
  }
}

 

// cross
int Cross ()
{
  int I, J, n-;
  char m;
  the printf ( "Please Enter The Order Number ODD (odd-order Enter):");
  Scanf ( "% D", & n-);
  fflush (stdin); // Clear cache
  printf ( "Please enter the character (enter character):");
  Scanf ( "% C", & m);
  IF (n-<= 0)
  the printf ( "\ T \ T \ ! TInput Error \ n-");
  for (I =. 1; I <= n-; I ++)
  {
    for (J =. 1; J <= n-; J ++)
    {
      IF (n-|| J == I == (n-+ 1) / 2)
      / * normal circumstances this is wrong, should be (j == (n + 1) / 2 || i == (n + 1) / 2), but since the interface
      problem, for aesthetics I choose to expand the spacing of the horizontal, the vertical character print more rearward * /
      printf ( "% c", m);
      the else
        printf ( "");
    }
    printf("\n");
  }
}

  

// open square
int Hollow_square ()
{
  int I, J, n-;
  char m;
  the printf ( "Please Enter The Order Number (Enter order):");
  Scanf ( "% D", & n-);
  fflush (stdin ); // Clear cache
  printf ( "Please enter the character (enter character):");
  Scanf ( "% C", & m);
  IF (n-<= 0)
  the printf ( "\ T \ T \ TInput Error ! \ n-");
  for (I =. 1; I <= n-; I ++)
  {
    for (J =. 1; J <= n--. 1; J ++)
    IF (J == I ==. 1. 1 || I || n-==)
      the printf ( "% C", m);
    the else
      the printf ( "");
    the printf ( "% C \ n-", m);
  }
}

 

// solid parallelogram
int Solid_parallelogram ()
{
  int I, J, K, n-;
  char m;
  the printf ( "Please Enter The Order Number (Enter order):");
  Scanf ( "% D", & n-);
  fflush (stdin); // Clear cache
  printf ( "Please enter the character (enter character):");
  Scanf ( "% C", & m);
  IF (n-<= 0)
    the printf ( "\ T \ T ! \ TInput Error \ n-");
  for (I =. 1; I <= n-; I ++)
  {
    for (J =. 1; J <= Ni; J ++)
    the printf (" ");
    for (K =. 1; K < n-=; ++ K)
      the printf ( "% C", m);
    the printf ( "\ n-");
  }
}

Guess you like

Origin www.cnblogs.com/tenfly/p/11455687.html