![]() |
|
#1
|
|||
|
|||
Hey guys I need help solving this problem urgently so please respond!I have a problem programming the following problem... I cant find a way to program it! Please Help! Here it is...
/* Input the value for an integer variable X and output all the factors of X (not including X itself). Example, if X is 6, then the program should output the numbers 2 and 3.*/ I have to do it with a while loop using C not C++. Thanks for your help in advance! Last edited by LuciWiz : 11-Aug-2005 at 04:42.
Reason: edited title
|
|||
|
#2
|
|||
|
|||
|
Here's a hint:
using the modulus operator provides you with the remainder after division. So, 5 % 3 --> 2 So loop through your range checking the results of a modulus operation. |
|
#3
|
|||
|
|||
|
Quote:
Thanks L7sqr but I tried that already and infact, this as far as I got, the program doesn't work correctly though... #include <stdio.h> #include <conio.c> main () { int X, Factor = 1; printf ("Enter a Number: "); scanf ("%i",&X); clrscr(); printf ("The factors of %i are : \n",X); while (Factor <= (X/2)) { if (X % Factor == 0) printf ("%i\n",Factor); Factor++; } getch(); } |
|
#4
|
|||
|
|||
|
Quote:
What do you mean by, "Doesn't work correctly"? "Gives the wrong answer"? "Crashes"? Maybe "doesn't compile? In general, you can have better chances for help if you ask the right question. Like, "When I gave it a value of 42, it said the factors are 6 and 9," for example. Or, more likely for your case, post the code first and tell us something like, "When I tried to compile this program with Borland bcc32 it gave the following error message." Quote:
Where is conio.c, and why are you #including it? Maybe you meant <conio.h> ??? From your first post, o one could possible have guessed what kind of help we could offer. So, besides wasting bandwidth, you lost some time getting help by not asking the right question in the right way. Regards, Dave |
|
#5
|
|||
|
|||
|
Quote:
Hey Dave thanks for your post. Infact, yes I wasn't clear with question. I use conio.c for clrscr. The compiler I used Dev-C++ v4 somethimes bugs a bit. The coding was right... I tried to save the exact file in another name and it compiled perfectly. Thanks anyway guys! |
|
#6
|
|||
|
|||
|
Quote:
The following is generally accepted as "good programming practice": Multiple C source files should be compiled separately and linked together by linker options. (Create a project and make source files all part of the project, if you are using a GUI.) In general, including C source files in other C source files can lead to lots of problems that have nothing to do with "compiler bugs". You have apparently resolved your problem to your satisfaction for this example, but you may come to grief if you do this in your future efforts. Just my opinion, of course. Regards, Dave |
Recent GIDBlog
R for statistics by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
| Help in solving this C++ problem..... | homz | C++ Forum | 3 | 24-May-2004 22:04 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The