Write a program which finds the factorial of a number entered by the user. (check for all conditions) (Beginner).
void findfactor(const unsigned int number)
{
unsigned int n = number;
printf("The factors ot the input number are:\n");
if (0 == n) {
printf("%d\n", n);
return;
}
for(unsigned int i = 1; i < n / i + 1; i++) {
if (n % i == 0 ) {
printf("%d\n", i);
printf("%d\n", n / i);
}
}
}
You can see, that I don't store the factors. Acturally, I don't
know how to store the factors. The number of the factors are
unknown. I can't use fixed size array to store. What about list, stack
or dynamic array? Yeah, they could solve this problem. But if you
are in an interview, and you are not allowed to use these
encapsulated data structure, you may implement these at that time?
And it's a question for beginner, maybe I should use some beginner's
way.
Create a program which generates fibonacci series till a number 'n' where 'n' is entered by the user. For eg. if the user enters 10 then the output would be: 1 1 2 3 5 8 (beginner)
void generate(int a, int b)
{
int total = a + b;
if (total < n) { //n is the number inputed by user
printf("total = %d\n", total);
generate(b, total);
}
}
Storing the data is a question. And if the question is "Create a
program which begin to generate fibonacci series untill a number 'n'
is entered by the user. Then output the series below n.", is it still for
beginner ?
:( Some basic questions still make me feel uneasy, the way is long
long...