A lot of people first feel must be: very simple ah, not just write a few printf statements
Like this:
#define _crt_secure_no_warnings 1
#include <stdio.h>
int main ()
{
printf (" *\n");
printf (" ***\n");
printf ("*****\n");
printf ("*******\n");
printf ("*****\n");
printf (" ***\n");
printf (" *\n");
System ("pause");
return 0;
}
It seems to be complete, but if I let you print this diamond is very large, there are many rows, many columns (20 rows, 20 columns), you need a lot of asterisks to do, you have to write this. It's too much trouble.
In fact, as long as found the law ——-when should be printed space, when should print an asterisk, packaged into a function, you can write a write only once, no matter how many rows and columns can be used to use the program, the following is a program such as:
#define _crt_secure_no_warnings 1
#include <stdio.h>
void pr_start (int _num)
{
int n=0;
int i = 0;
for (n = 1; n <= 2*_num; n++)
{
int temp = n;
if (n > _num)
{
Temp-= 2 * (n-_num);
}
for (i = 1; i < 2 * _num; i++)
{
if (i>= (_num-temp + 1)) && (i<= (temp + _num-1)) //Find Value
{
printf ("*") is required to output * time I;
}
else
{
printf ("");
}
}
printf ("\ n")
;
}
int main ()
{
int num = 0;
printf ("Please enter a number:");
scanf ("%d", &num);
Pr_start (num);
System ("pause");
return 0;
}
7 Rows, 7 columns:
59 rows, 59 columns:
Program only write once, want to output a n row n column of diamond, only need to enter a (n+1)/2 of the number can be.
The key to the program is to determine when the output ' * ', when the output ' (space).
for (n = 1; n <= 2*_num; n++)
{
int temp = n;
if (n > _num)
{
Temp-= 2 * (n-_num);
}
for (i = 1; i < 2 * _num; i++)
{
if (i>= (_num-temp + 1)) && (i<= (temp + _num-1)) //Find needed Output * Time I's value
{
printf ("*");
}
else
{
printf ("");
}
}
}
The above code is the essence of this program to achieve the function, input ' * ' and input ' of the law is also in this area. Here do not give a summary, please draw their own conclusions.
Of course, more than one law, you can think more, to think about what methods can be achieved.