Earn Higher Grades With Instant Assignment Help.Ask Question!

C Programming
(5/5)

Implement function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal values) of integer types char, short, int, long, and long long, both signed and unsigned

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS
  1. Implement function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal values) of integer types char, short, int, long, and long long, both signed and unsigned. You should do this by printing appropriate constants defined in header file <limits.h> located in directory /usr/include. Your output should be similar to:

signed char
minimum value: -128
maximum value: 127

unsigned char
minimum value: 0
maximum value: 255

signed short
minimum value: -32768
maximum value: 32767

... (and so on)

Note: The conversion specifiers for signed and unsigned long are li and lu, respectively. The conversion specifiers for signed and unsigned long long are lli and llu, respectively. The minimum value for unsigned integers is always 0 and therefore not defined in header file <limits.h>.

  1. Implement function types that takes no input, declares 3 variables of type char, 3 of type short, 3 of type int, and 3 of type double---in that order---and prints the addresses of the 12 variables---in the same order---in both hex (use %p conversion specifier) and unsigned long format.

&a1 = 0x7ffd45e3ac0f, 140725776002063
&a2 = 0x7ffd45e3ac0e, 140725776002062
&a3 = 0x7ffd45e3ac0d, 140725776002061
&b1 = 0x7ffd45e3ac0a, 140725776002058
&b2 = 0x7ffd45e3ac08, 140725776002056
...

  1. Implement function input_output that prompts the message "Enter your name: ", takes a name from the user as input, and then prints Hello <name> (replace <name> with the name that the user entered). You should use the function printf to display the message, allocate memory for a null-terminated string of length up to 31 characters using char name[32], and then use the function fgets to read the input into the string, e.g. fgets(name, sizeof(name), stdin). To find out more information on the usage of fgets, you can read the Linux online manual page with the command man fgets. Below is a sample execution of the function:

Enter your name: John
Hello John

  1. Implement function area that prompts the user for the height and width of a rectangle, and then calculates and prints the area of the rectangle. You should allocate a string called height_string for the height, a string called width_string for the width, and use fgets to read user's input into height_string and width_string, respectively. To calculate the area of the rectangle, you need to convert the strings into integers and then multiply the integers. You should allocate an integer called height for the height and an integer called width for the width using int height, width, and then do the conversions using the function strtol, e.g. height=strtol(height_string, NULL, 10). A sample execution of the function is as below:

What is the height? 15
What is the width? 20
The area is 300.

  1. Implement function sum. In the function, make an array of integers containing integers from 1, 2, 3, ..., 10 and store it in a variable data. You can create the array and declare a variable data_len that contains the length of the array with the following code:
  1. int data[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  • size_t data_len = sizeof (data) / sizeof(data[0]);

Then declare an integer variable sum, use a for loop to print each integer in data, sum up all the numbers in data into sum, and print out the value of sum like below:

  

1

2

3

4

5

6

7

8

9

10

sum: 55

       

Note that the C for loop is different from the Python for loop. The C for loop contains three expressions: an initializer such as int j = 0, a test such as j < data_len, and an update such as j++. The initializer is executed once initially. The test is run before each iteration of the body, and the body is only executed if the test succeeds. The update is run after each iteration of the body.

 

Attachments:
(5/5)

Related Questions

Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
545 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
949 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
758 Answers Hire Me