// Limits
// Daniel Pereira, 04 November 2022.
// Use limits.h and float.h to access MIN and MIX variables.
#include <stdio.h>
#include <limits.h> // limits on integer types
#include <float.h> // limits on floating point types
int main(int argc, char* argv[])
{
printf("INTEGER TYPE, MIN, MAX.\n");
printf("-----------------------\n");
printf("char, %d, %d\n", CHAR_MIN, CHAR_MAX);
printf("unsigned char, NA, %u\n", UCHAR_MAX);
printf("short, %d, %d\n", SHRT_MIN, SHRT_MAX);
printf("unsigned short,NA,%u\n", USHRT_MAX);
printf("int, %d, %d\n", INT_MIN, INT_MAX);
printf("unsigned int, NA, %u\n", UINT_MAX);
printf("long, %ld, %ld\n", LONG_MIN, LONG_MAX);
printf("unsigned long, NA, %lu\n", ULONG_MAX);
printf("long long, %lld, %lld\n", LLONG_MIN, LLONG_MAX);
printf("unsigned long long, NA, %llu\n\n", ULLONG_MAX);
printf("FLOATING POINT TYPE, MIN, MAX.\n");
printf("------------------------------\n");
printf("Float MIN: %.3e\n", FLT_MIN);
printf("Float MAX: %.3e\n", FLT_MAX);
printf("Double MIN: %.3e\n", DBL_MIN);
printf("Double MAX: %.3e\n", DBL_MAX);
printf("Long Double MIN: %.3Le\n", LDBL_MIN);
printf("Long Double MAX: %.3Le\n", LDBL_MAX);
printf("Number of decimal digits precision of float: %u\n", FLT_DIG);
printf("Number of decimal digits precision of double: %u\n", DBL_DIG);
printf("Number of decimal digits precision of long double: %u\n", LDBL_DIG);
return 0;
}
// climits <limits.h>
// https://devdocs.io/cpp/header/climits
// This header was originally in the C standard library as <limits.h>.
//
// This header is part of the type support library, in particular it's part of the C numeric limits interface.
// <float.h>
// https://www.tutorialspoint.com/c_standard_library/float_h.htm
//
// The float.h header file of the C Standard Library contains a set of various platform-dependent constants related to floating point values. These constants are proposed by ANSI C. They allow making more portable programs.
View my playlist of Commodore 64 games videos. They are all several minutes in length, and show enough of each game to serve as a preview for those who are looking for retro games to try.
https://github.com/pereiradaniel/beginning_c/blob/master/ch2/exercises/2_4/exercise2_4.c // Exercise 2-4 // Write a program that prompts for the user’s weekly pay in dollars and the // hours worked to be entered through the keyboard as floating-point values. The program // should then calculate and output the average pay per hour in the following form: // Your average hourly pay rate is 7 dollars and 54 cents. #include <stdio.h> double checkInput(double input, double min, double max); int main(int argc, char* argv[]) { double hours = 0, rate = 0; // Get input for hours: printf("Enter number of hours worked: "); while(hours == 0) { scanf(" %lf", &hours); hours = checkInput(hours, 1, 10000); } // Get input for salary: printf("Enter hourly rate: "); while(rate == 0) { scanf(" %lf", &rate); rate = checkInput(rate, 1, 100); } // Calculate pay:...
The char type in C is an integer which gets decoded as a character. You can print the char's numerical type. https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.c // Chars // Daniel Pereira, 16 November 2022. // Display a char and it's numerical value. #include <stdio.h> int main(int argv, char* argc[]) { char c = 0; printf("Enter a character: \n"); scanf(" %c", &c); printf("The character: %c\nIt's numerical value: %d\n", c, c); return 0; } https://github.com/pereiradaniel/beginning_c/blob/master/ch2/char.txt ==87== Memcheck, a memory error detector ==87== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==87== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==87== Command: ./char ==87== Enter a character: X The character: X It's numerical value: 88 ==87== ==87== HEAP SUMMARY: ==87== in use at exit: 0 bytes in 0 blocks ==87== total heap usage: 2 al...