Question

Using C: Implement the function ranges that takes no input and prints the ranges (i.e., the...

Using C:

Implement the function ranges that takes no input and prints the ranges (i.e., the minimum and maximum legal values) of the types char, short, int, long, and long long, both signed and unsigned. You should do this by printing appropriate constants defined in the header file /usr/include/limits.h (this is why hw1.c starts with #include <limits.h>). This should print something like:

signed char
minimum value: -128
maximum value: 127

unsigned char
minimum value: 0
maximum value: 255

signed short
minimum value: -32768
maximum value: 32767

Void ranges() {

//IMPLEMENT THIS

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

VERY IMPORTANT NOTES: These limits may vary depend on the version of the compiler you are using. LLONG_MIN, LLONG_MAX and ULLONG_MAX are introduced in compiler version C99, so old compilers may not support them. In some compilers int & short int have the same range, while in some other compilers, int and long types have the same range. Also, the definitions for format specifiers used in this code are below.

%d – int

%u – unsigned int

%ld – long int

%lu – unsigned long int

%lld – long long int

%llu – unsigned long long int

//CODE

#include<limits.h>

#include<stdio.h>

void ranges(){

              //char-signed

              printf("signed char\n");

              printf("minimum value: %d\n",SCHAR_MIN);

              printf("maximum value: %d\n",SCHAR_MAX);

             

              //char-unsigned

              printf("\nunsigned char\n");

              printf("minimum value: %d\n",0);

              printf("maximum value: %d\n",UCHAR_MAX);

             

              //short-signed

              printf("\nsigned short\n");

              printf("minimum value: %d\n",SHRT_MIN);

              printf("maximum value: %d\n",SHRT_MAX);

             

              //short-unsigned

              printf("\nunsigned short\n");

              printf("minimum value: %d\n",0);

              printf("maximum value: %d\n",USHRT_MAX);

             

              //int-signed

              printf("\nsigned int\n");

              printf("minimum value: %d\n",INT_MIN);

              printf("maximum value: %d\n",INT_MAX);

             

              //int-unsigned

              printf("\nunsigned int\n");

              printf("minimum value: %d\n",0);

              printf("maximum value: %u\n",UINT_MAX);

             

              //long-signed

              printf("\nsigned long\n");

              printf("minimum value: %ld\n",LONG_MIN);

              printf("maximum value: %ld\n",LONG_MAX);

             

              //long-unsigned

              printf("\nunsigned long\n");

              printf("minimum value: %lu\n",0l);

              printf("maximum value: %lu\n",ULONG_MAX);

             

              //long long-signed

              printf("\nsigned long long\n");

              printf("minimum value: %lld\n",LLONG_MIN);

              printf("maximum value: %lld\n",LLONG_MAX);

             

              //long long-unsigned

              printf("\nunsigned long long\n");

              printf("minimum value: %llu\n",0ll);

              printf("maximum value: %llu\n",ULLONG_MAX);

             

              //Note: LLONG_MIN,LLONG_MAX and ULLONG_MAX are introduced in compiler version C99

              //so old compilers may not support them.

}

int main(){

              ranges();

              return 0;

}

/*OUTPUT (using one compiler (DevC++))*/

signed char

minimum value: -128

maximum value: 127

unsigned char

minimum value: 0

maximum value: 255

signed short

minimum value: -32768

maximum value: 32767

unsigned short

minimum value: 0

maximum value: 65535

signed int

minimum value: -2147483648

maximum value: 2147483647

unsigned int

minimum value: 0

maximum value: 4294967295

signed long

minimum value: -2147483648

maximum value: 2147483647

unsigned long

minimum value: 0

maximum value: 4294967295

signed long long

minimum value: -9223372036854775808

maximum value: 9223372036854775807

unsigned long long

minimum value: 0

maximum value: 18446744073709551615

/*OUTPUT (using another compiler (online))*/

signed char

minimum value: -128

maximum value: 127

unsigned char

minimum value: 0

maximum value: 255

signed short

minimum value: -32768

maximum value: 32767

unsigned short

minimum value: 0

maximum value: 65535

signed int

minimum value: -2147483648

maximum value: 2147483647

unsigned int

minimum value: 0

maximum value: 4294967295

signed long

minimum value: -9223372036854775808

maximum value: 9223372036854775807

unsigned long

minimum value: 0

maximum value: 18446744073709551615

signed long long

minimum value: -9223372036854775808

maximum value: 9223372036854775807

unsigned long long

minimum value: 0

maximum value: 18446744073709551615

Add a comment
Know the answer?
Add Answer to:
Using C: Implement the function ranges that takes no input and prints the ranges (i.e., the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ***The following is to be written in C:**** ****The following is the sizeof.c program that needs...

    ***The following is to be written in C:**** ****The following is the sizeof.c program that needs to be modified:**** ****Section B11 the question asks to refer to:**** Modify the sizeof.c program (in the sizeof folder on github) and show the data range (min and max) in addition to the size of the data types in a nice table (print one line for each data type). Refer to section B11 in your textbook (page 257) for getting min and max values...

  • Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code...

    Using Microsoft Visual Studio. 1) Complete the following C++ program by adding more line of code for 8-bit signed array, 16-bit unsigned array, 16-bit signed array, 32-bit signed array and 32-bit signed array. 2) Fill in all the blanks in Table 1 using your completed code, following the hints provided within the table. 3) Fill in all the blanks in Table 2 using your completed code, following the hints provided within the table. C++ Program #include <stdio.h> #include <iostream> int...

  • I need to implement a program that requests a x,y point and the radius of a...

    I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...

  • devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include...

    devmem2.c #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <errno.h> #include <signal.h> #include <fcntl.h> #include <ctype.h> #include <termios.h> #include <sys/types.h> #include <sys/mman.h>    #define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \ __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0) #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) int main(int argc, char **argv) { int fd; void *map_base = NULL, *virt_addr = NULL; unsigned long read_result, writeval; off_t target; int access_type = 'w';    if(argc...

  • Design and implement a C version of the color match program. As a starting point, use...

    Design and implement a C version of the color match program. As a starting point, use the file HW2-1-shell.c. The program should employ a reasonable algorithm that compares all pairings of colors in the palette exactly once. A color should not be compared to itself. Nor should two colors be compared to each other more than once. Your C program should print out the total component color difference for the closest pair using the print string provided in the shell...

  • For this computer assignment, you are to write a C++ program to implement a class for...

    For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. The definition of the class for a binary tree (as a template) is given as follows: template < class T > class binTree { public: binTree ( ); // default constructor unsigned height ( ) const; // returns height of tree virtual void insert ( const T& ); //...

  • please provide full answer with comments this is just begining course of c++ so don't use...

    please provide full answer with comments this is just begining course of c++ so don't use advanced tequenicks I'll put main.cpp, polynomial.h, polynomial.cpp and Cimg.h at the bottom of pictures. If you help me with this will be greatly thankful thank you main.cpp #include "polynomial.h" #include "polynomial.h" #include "polynomial.h" #include "polynomial.h" #include <iostream> using std::cout; using std::endl; int main() { pic10a::polynomial p1; p1.setCoeff(0, 1.2); p1.setCoeff(3, 2.2); p1.setCoeff(7, -9.0); p1.setCoeff(7, 0.0); //degree of polynomial is now 3 cout << p1 <<...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • Please include function in this program Write a C program that will calculate the gross pay...

    Please include function in this program Write a C program that will calculate the gross pay of a set of employees utilizing pointers instead of array references. You program should continue to use all the features from past homeworks (functions, structures, constants, strings). The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below. The program determines the overtime hours (anything over 40 hours), the gross pay and...

  • Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be...

    Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book tit le, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT