Starting from:

$29

Assignment 1 & 2: A Fibonacci sequence

CS 220, Fall 2017 Assignment 1 & 2 – (200 points)
 Ensure that your code runs on remote.cs.binghamton.edu. • Useful resources: 1. Commonlinuxcommands: http://www.informit.com/blogs/blog.aspx?uk=The10-Most-Important-Linux-Commands 2. http://c-faq.com/
Questions 1. A Fibonacci sequence is a series of numbers: 0, 1, 1, 2, 3, 5, 8, ... where: The first number is 0, the second number is 1, and each successive number is foundbyaddingthetwoprecedingnumbers. Writeafunctionwithname“isFib” that accepts an integer i as input and returns n such that i is the nth Fibonacci number. If i isnot a Fibonacci number, the function returns -1. Assume 0 ≤ i ≤ 1000000000. If i is 1, return 2. Use the prototype: int isFib(unsigned long i); (40 points) 2. Ifthenumbers1to5arewrittenoutinwords: OnE,twO,thrEE,fOUr,fIvE,then thereare2+1+2+2+2=9vowelsusedintotal. Writeafunction unsigned int count vowels(unsigned long num); that accepts a number as inputandreturnsthesumofallvowelswhenthenumberiswrittenoutinwords. 0 ≤ num ≤ 1000000000. Return 0 if input is invalid. NOTE: Do not count ‘and’ in the expansion of the word. For example, 342 (thrEE hUndrEd and fOrty-twO) contains 6 vowels and 115 (OnE hUndrEd and fIftEEn) contains 7 vowels. 1500 is OnE thOUsAnd fIvE hUndrEd (not fifteen hundred) contains 9 vowels. (60 points)
1
3. Writeafunctionunsigned int count ones(long n)thatacceptsa64bit integernandreturnsthenumberof1’sinthebinaryrepresentationofthenumber (2’s complement representation for negative numbers). (40 points) 4. Writeafunctionunsigned long swap bytes(unsigned long n)that accepts an 8-byte integer, swaps bytes 1 and 2, 3 and 4, 5 and 6, and 7 and 8 and returns the result. (40 points) Example: ifn=0x12345678deadbeef,swap bytesreturns0x34127856addeefbe. 5. Writeafunctionlong a4 minus b4(int a, int b)thatreturnsa4−b4. Do not use math library. Assume−100 ≤ a,b ≤ 100 (20 points)

More products