Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 4 Create a C-program that uses the fact that 0 (zero) is interpreted as FALSE and non-zero is interpreted as TRUE. The C-program can

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Exercise 4 Create a C-program that uses the fact that 0 (zero) is interpreted as FALSE and non-zero is interpreted as TRUE. The C-program can be made easier to read when this 0 (or non- zero) is assigned to a variable e.g. an int called married. Use the ?: operator to print if someone is married or not. (See if you can use a single printf) Exercise 6 Write a C-program that shifts any number two places to the right. Input should be an integer. Output should be the shifted result, as well as output an indication of whether a logical or arithmetic shift is performed (if a 1 or o is shifted in at the left side) for the inputted number. For more info and example, see http://en.wikipedia.org/wiki/Logical shift Exercise 7 Write a C-program that efficiently multiplies a number by a factor 2 to the power n. The number to multiply and n are variables, which get a value at the start of the program. Clue: 1 shift to the left is the same as multiplying by 2. 2 shifts to the left are the same as multiplying by 4. 3 shifts to the left are the same as multiplying by 8.Exercise 1 Write a C-program that asks for text input from the keyboard. The output of this program should be the amount of characters, the amount of words and the amount of newlines that have been typed. Multiple consecutive spaces shouldnot be counted as multiple words. Reading keys from the keyboard is possible by using the function getcharO. The reading of characters from the keyboard can be stopped when the shutdown-code "D (CTRL + D) is entered. "D has the ASCII-value 4 (see forum discusson on this exercise). Use a while loop. Exercise 3 Rewrite the C-program that was written for exercise 1, but use do While instead of while. Exercise 3 Do exercise 1 again, but change your solution so that the switch-case statement is used instead of the if blocks. Exercise 3 Write a program that consists of two source-files. The first (Main.c) contains the main() function and gives the variable ia value. The second source-file (Print.c) multiplies i by 2 and prints it. Print.c contains the function print() which can be called from main(). Exercise 4 Write a recursive function printnumber() which gets the number to be printed. This number is an integer. The function should print the number digit by digit by using the putchar() function. Don't use printf(). Tips: Use the modulo operator (%) to determine the digit to print. Use the division operator (/) to calculate the argument for the recursive call. Don't forget to handle negative numbers correctly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

3 What are likely to be the market targets of interest?

Answered: 1 week ago