Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code must be in C programming language. 1. Implement function ranges that takes no input and prints the ranges (i.e., the minimum and maximum

This code must be in C programming language.

image text in transcribed

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 macros defined in header file located in directory /usr/include. You should NOT use integer constants directly, except for zero. 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 . 2. Implement four versions of a function prt_triangle that takes a positive integer n as input argument and prints a triangle of length n with asterisks (*): using a for loop in prt_triangle1, using a while loop in prt_triangle2, using a do-while loop in prt_triangle3, and using recursion in prt_triangle4. Your output for the included test code should be:

prt_triangle1(3) * * * * * * prt_triangle2(3) * * * * * * prt_triangle3(3) * * * * * * prt_triangle4(3) * * * * * *

3. Implement function guess_num that generates a random integer number between 0 and 100 and lets the user guess the number. The function performs three major steps. First, it generates a random integer number num using the rand function. Second, it prompts the message Enter your guess: and takes a number from the user as input. Third, it checks whether the number entered by the user is identical to num. If so, it displays the message Congrats! Your guess is correct and exits. If the entered number is larger than num, it displays the message Your guess is too large. Try again. and goes back to step 2. If the entered number is smaller than num, it displays the message Your guess is too small. Try again. and goes back to step 2.

You can use the command man rand to find more information on how to use the rand function. A sample execution of the function is as below:

Enter your guess: 27 Your guess is too small. Try again. Enter your guess: 45 Your guess is too large. Try again. Enter your guess: 32 Congrats! Your guess is correct.

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Recognize the four core purposes service environments fulfill.

Answered: 1 week ago