#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
/* Clear the screen */
system("clear");
/* Insert your own code here below... */
while (1) {
do_it();
}
/* Hit a key to quit the program */
// printf("\n\n\nHit <enter> to quit the program...\n");
//getchar();getchar();
return 0;
}
int do_it( ) {
unsigned int t;
printf("Enter a positive integer seperated with a space. Finish with <enter>: \n");
scanf("%d",&t);
unsigned int orgval = t;
char dest[100];
char buffer[200] ;
while (t > 1) {
if ( t % 2 ) {
unsigned int temp = (3*t)+1;
char p[32];
t = temp;
sprintf(p,"%u, ",temp);
strcat(dest,p);
}
else {
unsigned int temp2 = t/2;
char p2[32];
t = temp2;
sprintf(p2,"%u, ",temp2);
strcat(dest,p2);
}
}
sprintf(buffer,"The Hailstone series produced is: %u, %s",orgval,dest);
printf(buffer);
printf("\nPress <enter> to continue..._\n\n");
getchar();getchar();
return 0;
}