TCES 201 Homework 2 – Control Structures solved

$24.99

Original Work ?

Download Details:

  • Name: Assignment-2-Control-Structures.zip
  • Type: zip
  • Size: 236.55 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (2 votes)

10 Points
This homework tests your understanding of the topics covered in the third week related to
C Programming – Control Structures.
1. Write a program to print m Fibonacci numbers where m is the input number of
Fibonacci numbers that need to be printed. Print each number. The formula for
Fibonacci is fibn = fibn-1+fibn-2.
Here’s a sample output:
Enter the number of Fibonacci numbers: 5
1: 1
2: 1
3: 2
4: 3
5: 5
2. Write a program to input a set of integer numbers, count and sum the positive
numbers, and also count and sum the negative numbers. It should then print the
count and sum of all positive numbers and the count and sum of all negative
numbers.
Here’s a sample output:
Enter a number: 5
Do you want to enter another number? y
Enter a number: -5
Do you want to enter another number? y
Enter a number: 10
Do you want to enter another number? y
Enter a number: 20
Do you want to enter another number? y
Enter a number: -20
Do you want to enter another number? n
You entered 3 positive numbers and their sum is 35
You entered 2 negative numbers and their sum is -25
3. (2 Points) Challenge Work – (Printing the Decimal Equivalent of a Binary Number)
Input an integer (5 digits or fewer) containing only 0s and 1s (i. e., a “binary”
integer) and print its decimal equivalent. [Hint: Use the remainder and division
operators to pick off the “binary” number’s digits one at a time from right to left.]
Here’s a sample output:
Enter binary integer: 1101
Decimal equivalent of 1101 is 13
Submission Instructions: Submit the code on Canvas under hw2 Submission link.
Submit the C source code files with the names fib.c and numbers_sum_count.c (and
decimal.c, if attempting challenge work).
Each program must contain a header in the following format.
/* Menaka Abraham
CES201
Autumn 2014
This program prints a simple Hello World to the console.
*/