Rootsource's Headquarters
IT, Developing, Networking and Tech News
Looking for Good Web Hosting
Search This Blog
Tuesday, October 03, 2006
3n + 1 problem
#include
int main(void)
{
int num;
printf("insert number:\n");
scanf("%d", &num);
printf("%d ", num);
while(num != 1)
{
if ((num%2) == 0)
{
num = num / 2;
}
else
{
num = (3 * num) + 1;
}
printf("%d ", num);
}
printf("\n");
}
Newer Posts
Older Posts
Home
Subscribe to:
Posts (Atom)