Creative Commons License Foxbond's Repo

/** (c) 2015 Michał (Foxbond) Chraniuk */
#include <stdio.h>
#include <stdlib.c>
int max=0;
int elem=0;


int f (int n){
     int temp;
 		 if (n==1){
		 		//printf("%d", n);
		 		return;
     }
     if (n % 2 == 0){
 	      temp = n/2;
     }else{
		 		temp=3*n+1;	 
     }
     ++elem;
     if (temp > max) max=temp;
     
     printf("%d ", temp);
     f(temp);
}


int main (){
		int n;
		do {
			 printf("Podaj n (wieksze od 0): ");
		   scanf("%d", &n);
	  }while(n<0);
	  printf("Ciag: ");
		f(n);
		printf("\nLiczba elementow ciagu: %d\nNajwieksza wartosc: %d", elem, max);
		getch();
		return 0;
}


> Back