tomasf1234

Donovic Progress 1

Jun 4th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. //prints numbers as required by richard.
  2. //Tomas Donovic 27/3/
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. int printWondrous (int start);
  6.  
  7. int main(){
  8.     printWondrous(3);
  9.  
  10.     return EXIT_SUCCESS;
  11. }
  12. int printWondrous (int start){
  13.     int currentval = start;
  14.     printf("%d ",currentval);
  15.     int counter = 1;
  16.     while(currentval > 1){
  17.         if((currentval % 2) != 0){
  18.             currentval = currentval * 3;
  19.             currentval ++;
  20.         }else{
  21.             currentval = currentval / 2;
  22.         }
  23.         printf("%d ",currentval);
  24.         counter ++;
  25.     }
  26.     printf("\n");
  27.     return counter;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment