# Do some boring questions when you are bored

Source: Internet
Author: User

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;

}*/

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.