I wrote it myself. If the code is poor, I hope you can point out that brother is just a side dish. Here we will collect the questions that I think I need to spend some time on. The questions will be accumulated constantly, so that you can continuously accumulate programming experience and some programming skills and ideas.
1. Implement a function and pass an integer parameter. If the integer can be decomposed into consecutive natural numbers, all possible outputs will be generated. Otherwise, the output cannot be decomposed.
For example:
Input: 15
Output:
15 = 1 + 2 + 3 + 4 + 5
15 = 4 + 5 + 6
15 = 7 + 8
Input: 4
Output: cannot be decomposed
Brother's source code:
# Include <stdio. h>
Void func (N)
{
Int I;
Int J;
Int sums;
Int flag = 0;
Int K;
Int show = 0;
For (I = 1; I <= n/2; I ++)
{
Flag = 0;
Sums = 0;
For (j = I; j <= n/2 + 1; j ++)
{
Sums + = J;
If (sums = N)
{
Flag = 1;
Show = 1;
Break;
}
}
If (flag = 1)
{
Printf ("% d =", N );
For (k = I; k <= J; k ++)
{
Printf ("% d", k );
If (k <j) printf ("+ ");
}
Printf ("\ n ");
}
}
If (show = 0)
Printf ("cannot be broken down ");
}
Int main (void)
{
Int N;
Scanf ("% d", & N );
Func (N );
Return 0;
}
2. Implement a function, pass an integer parameter, return the number of zeros at the end of the factorial of this integer parameter, and output them in the main function.
For example:
Input: 9
Output: 1
Input: 3
Output: 0
Input: 788
Output: 195
Brother's source code:
/* # Include <stdio. h>
# Include <math. h>
Int sum (int n)
{
Int I = 0;
Int J = 0;
Int S = 0;
Int B = N;
While (n> = 5)
{
N/= 5;
I ++;
}
For (j = 1; j <= I; j ++)
{
S + = B/POW (5, J );
}
Return S;
}
Int main (void)
{
Int N;
Scanf ("% d", & N );
Printf ("% d", sum (n ));
Return 0;
}*/