What's Here?
- Members: 244,263
- Replies: 693,078
- Topics: 113,148
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,241
- Members: 69
- Guests: 1,172
|
This recursive function can find factors of a number.
|
Submitted By: born2c0de
|
|
Rating:
|
|
Views: 5,966 |
Language: C++
|
|
Last Modified: July 29, 2006 |
Snippet
/*
Written originally by Sanchit Karve AKA born2c0de
*/
#include <iostream>
#include <conio>
void factors(long n,long f=1)
{
if(n%f==0)
cout<<f<<" ";
if(f==n)
return;
factors(n,f+1);
}
int main()
{
factors(37271);
getch();
return 0;
}
Copy & Paste
|
|
|
Be Social
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|