Created
March 25, 2018 06:51
-
-
Save manu354/818ba006493b327cb8c288f2acbf13c5 to your computer and use it in GitHub Desktop.
wondrous.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * doomsday.c | |
| * A program to test a function dayOfWeek which determines which | |
| * day of the week a particular date falls on. | |
| * (only for dates after the start of the Gregorian calendar). | |
| * | |
| * Program stub created by Richard Buckland on 17/03/14 | |
| * This program by YOUR-NAME-HERE | |
| * Freely licensed under Creative Commons CC-BY-3.0 | |
| * | |
| * | |
| */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <assert.h> | |
| int printWondrous(int start); | |
| int main(int argc, char *argv[]) { | |
| // printf("\n %d", printWondrous(1)); | |
| return EXIT_SUCCESS; | |
| } | |
| // given the doomsday for a year, and whether or not it is a | |
| // leap year, this function return the day of the week for any | |
| // given month and day in the year. | |
| // | |
| //int runWonder(int num, int count){} | |
| int count; | |
| int printWondrous(int start) { | |
| int num = start; | |
| if(!count) count = 1; | |
| printf("%d ", num); | |
| int newNum = 0; | |
| if(num != 1) { | |
| if (num % 2 == 0) { | |
| newNum = num / 2; | |
| } else { | |
| newNum = num * 3 + 1; | |
| } | |
| count++; | |
| } | |
| else { | |
| printf("\n"); | |
| return count; | |
| } | |
| return printWondrous(newNum); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment