| | |
My solution to 2 beginner questions
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2007
Posts: 16
Reputation:
Solved Threads: 0
- ••••
Write a program which finds the factorial of a number entered by the user. (check for all conditions) (Beginner).
C++ Syntax (Toggle Plain Text)
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)
C++ Syntax (Toggle Plain Text)
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...
Last edited by kinggarden; Jun 6th, 2007 at 11:27 am.
Rock Mu
I will keep walking!
Shanghai, China
I will keep walking!
Shanghai, China
>And it's a question for beginner, maybe I should use some beginner's way.
Maybe you should read the question more carefully.
The problem asks you to calculate a factorial (that is, N!), not the factors of a given number. You're trying to solve the wrong problem.
>Storing the data is a question.
Why?
>is it still for beginner ?
Yes, the Fibonacci series is very easy to calculate.
Maybe you should read the question more carefully.
The problem asks you to calculate a factorial (that is, N!), not the factors of a given number. You're trying to solve the wrong problem.>Storing the data is a question.
Why?
>is it still for beginner ?
Yes, the Fibonacci series is very easy to calculate.
Last edited by Narue; Jun 6th, 2007 at 12:00 pm.
I'm here to prove you wrong.
•
•
Join Date: Jun 2007
Posts: 16
Reputation:
Solved Threads: 0
•
•
•
•
>And it's a question for beginner, maybe I should use some beginner's way.
••••Maybe you should read the question more carefully.The problem asks you to calculate a factorial (that is, N!), not the factors of a given number. You're trying to solve the wrong problem.
Sorry, I misunderstood the question.
>Storing the data is a question.
Because I think I don't know the amount of the data, so I have to••••Why?
use some dynamic array to store the data. Right?
••••>is it still for beginner ?
Yes, the Fibonacci series is very easy to calculate.
A thread generates Fibonacci serials.
A thread listen to the input.
And the two threads have to communicate in some way.
Rock Mu
I will keep walking!
Shanghai, China
I will keep walking!
Shanghai, China
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
>Because I think I don't know the amount of the data, so I have to
>use some dynamic array to store the data. Right?
Wrong. Both factorials and Fibonacci numbers are a linear series. You can calculate them with a trivial loop. You're making things ridiculously complicated.
>use some dynamic array to store the data. Right?
Wrong. Both factorials and Fibonacci numbers are a linear series. You can calculate them with a trivial loop. You're making things ridiculously complicated.
I'm here to prove you wrong.
![]() |
Similar Threads
- VBScript Beginner Questions (Visual Basic 4 / 5 / 6)
- Sale: *50% Off*! Superb Value. Reliable. Great Features. 30 Day Money Back Guarantee! (Web Hosting Deals)
- $5 Hosting 3.5gb/40gbs!! 99.9% Uptime, 30 Day Money Back, Live Telephone/Chat Support (Web Hosting Deals)
- beginner (C++)
- Beginner's questions: C++ and databases (C++)
Other Threads in the C++ Forum
- Previous Thread: Question, basic encrpytion?
- Next Thread: Global, yet not global....
| Thread Tools | Search this Thread |
api array beginner bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion count database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







Sorry, I misunderstood the question.