cs1713-day1-prog1.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (C) 2020, 2019, 2018, 2017 Girish M
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. * MA 02110-1301, USA.
  17. *
  18. */
  19. /*-----------------------------------
  20. Name: Girish M
  21. Roll number: cs1713
  22. Date: 25 July 2017
  23. Program description: Write a program to determine the ranges of the generic C data types:
  24. char,int,float,double – both for unsigned and signed cases.Consider short and long data types too, wherever appropriate
  25. Acknowledgements:
  26. ------------------------------------*/
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <limits.h>
  30. #include <float.h>
  31. #include <inttypes.h>
  32. #include <stdint.h>
  33. int main(void)
  34. {
  35. printf("---------------------------------------------------");
  36. printf("\nSize of int is %ld, float is %ld, char is %ld, double is %ld bytes.\n", sizeof(int), sizeof(float), sizeof(char), sizeof(double));
  37. printf("\nSize of long is %ld bytes.\n", sizeof(long));
  38. printf("\nSize of short is %ld bytes.\n", sizeof(short));
  39. printf("\nSize of unsigned is %ld bytes.\n", sizeof(unsigned));
  40. printf("---------------------------------------------------");
  41. printf("\nRange of int is from %d to %d\n", INT_MIN, INT_MAX);
  42. printf("\nRange of float is from %e to %e\n", FLT_MIN, FLT_MAX);
  43. printf("\nRange of char is from %d to %d\n", CHAR_MIN, CHAR_MAX);
  44. printf("\nRange of double is from %e to %e\n", DBL_MIN, DBL_MAX);
  45. printf("\nRange of unsigned int is from %d to %u\n", 0, UINT_MAX);
  46. printf("\nRange of short is from %d to %d\n", SHRT_MIN, SHRT_MAX);
  47. printf("\nRange of long is from %ld to %ld\n", LONG_MIN, LONG_MAX);
  48. printf("---------------------------------------------------\n");
  49. return 0;
  50. }