Thank ya shiv, agarwal and Anders. On Sat, Jul 30, 2011 at 8:10 AM, Anders Ma <xuejiao...@gmail.com> wrote:
> anders@anders-Satellite-U400:~/puzzle$ cat novel_she_calf.c > #include <stdio.h> > > /* > iIf a cow produces its first she-calf at age two years and after that > produces another single she-calf every year, how many she-calves are > there after 12 years? assuming none die. > */ > > unsigned int she_calves(unsigned int year) > { > unsigned int one_year = 0; > unsigned int two_year = 1; > unsigned int tmp; > > while (year--) { > tmp = one_year; > one_year += two_year; > two_year = tmp; > } > return one_year + two_year - 1; > } > > int main (int argc, char** argv) > { > unsigned int number; > > if (argc != 2) { > printf("[usage]: she_calves [year]\n"); > return 0; > } > number = she_calves(atoi(argv[1])); > printf("After %d years, she-calves number is %d\n", atoi(argv[1]), > number); > } > anders@anders-Satellite-U400:~/puzzle$ gcc novel_she_calf.c -o she_calves > anders@anders-Satellite-U400:~/puzzle$ ./she_calves 12 > After 12 years, she-calves number is 232 > anders@anders-Satellite-U400:~/puzzle$ > > > > -- > Regards > Anders > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Regards Reynald Reni Masters in Software Engineering CIT - India -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.