![]() |
|
#11
|
|||
|
|||
|
Quote:
So: show us what your Prime() looks like. General Debugging Hint: before calling a function, put in a printf() to show what the value of the arguments are: so, in main() you would have something like: CPP / C++ / C Code:
Then, in Prime(), you would have something like CPP / C++ / C Code:
Get the idea? That makes sure that the function is working on what you think it should be working on. Next time: don't just describe the problem, please: Show us your code. Don't say, "I placed your code..." Say, "Here is the function, showing the code that I am using." Regards, Dave |
|||
|
#12
|
|||
|
|||
My Prime FunctionThanks Dave,
Here is my function for Prime: /* For prime */ int Prime(int num) { int n, IsPrim; IsPrim = 1; for(n = 2; n < num; n++); if ( num % n == 0) { IsPrim=0; printf("Divisor of prime\n"); } if(IsPrim) printf("It is Prim"); return n; } Quote:
|
|
#13
|
|||
|
|||
|
Quote:
Well, did you follow my suggestion and put the printf() in the main() program before calling Prime() and another printf() inside the Prime() function when it is entered? The idea is that you can debug your own code much faster than waiting for someone else to tell you. (I really don't mind trying to help, but I think you are better served by helping yourself.) (Please use code tags when posting code: put [c] before the first line of code, and put [/c] after the last line.) Look here for an explanation: http://www.gidforums.com/t-689.html Regards, Dave |
|
#14
|
|||
|
|||
|
Thanks Dave,
I did place your code in both places and I have been testing and trying to debug my code. Again, from the test I noticed that the loop or the prime function that I have created is missing something because it does not detect the prime. I have also been surfing the net for 2 hours trying to look at prime detection formulas and can't seem to get it. I apologize if you are frustrated and thank you for your time. I will figure out some how. I am new to this so I guess I will keep tackling it. jennifer Quote:
|
|
#15
|
|||
|
|||
|
Quote:
My point was that I don't see anything wrong with your Prime() function, but that doesn't have the printf() statement. Show me the code that you are running (including main() and its call to Prime). There is nothing fundamentally wrong with your Prime() detection function. There is some small detail that I can't possibly help you with unless I see what you are actually running. Regards, Dave |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two virtual hosts, cgi script behaves differently on each | blimbo | Apache Web Server Forum | 0 | 04-Aug-2004 10:35 |
| Where can I find web statistics script / software? | rhino1616 | Web Design Forum | 2 | 02-Jan-2004 21:31 |
| Redirect multiple URLs to one script, masking true URL | Maccaday | Apache Web Server Forum | 1 | 10-Dec-2003 09:34 |
| JavaScript Tutorial Part 1 | pcxgamer | Web Design Forum | 2 | 01-Dec-2003 10:16 |
| VALIDATING file types on an PHP upload script? | JdS | MySQL / PHP Forum | 0 | 02-Jan-2003 08:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The