GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Aug-2005, 03:29
EdgeGamer EdgeGamer is offline
New Member
 
Join Date: Aug 2005
Posts: 3
EdgeGamer is on a distinguished road
Question

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  
Old 11-Aug-2005, 05:06
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough
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  
Old 11-Aug-2005, 05:10
EdgeGamer EdgeGamer is offline
New Member
 
Join Date: Aug 2005
Posts: 3
EdgeGamer is on a distinguished road
Question

Quote:
Originally Posted by L7Sqr
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.

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  
Old 11-Aug-2005, 07:43
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by EdgeGamer
Thanks L7sqr but I tried that already and infact, this as far as I got, the program doesn't work correctly though...
#include <conio.c>


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:
Error E2209 factor.c 2: Unable to open include file 'conio.c'

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  
Old 11-Aug-2005, 09:11
EdgeGamer EdgeGamer is offline
New Member
 
Join Date: Aug 2005
Posts: 3
EdgeGamer is on a distinguished road
Smile

Quote:
Originally Posted by davekw7x
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."


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

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  
Old 11-Aug-2005, 09:35
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by EdgeGamer
The coding was right... I tried to save the exact file in another name and it compiled perfectly.


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 GIDBlogR for statistics by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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

All times are GMT -6. The time now is 18:59.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.