Skip to main content

C-Programming Program 1(c)

 1(c) Write a C program to Determine the ranges of char, short, int and long int variables both signed and  Unsigned 

Program


(i) By using size of


#include<stdio.h>

#include<math.h>
void main()
{
 int d,e;
 char c;
 short s;
 unsigned short u;
 int x;
 unsigned int y;
 long l,m;
 unsigned long n,p;
 d=pow(2,(sizeof(c)*8))/2;
 e=pow(2,(sizeof(c)*8))/2-1;
 printf("\nThe range of char is:%d to %d",d,e);
 d=pow(2,(sizeof(s)*8))/2;
 e=pow(2,(sizeof(s)*8))/2-1;
 printf("\nThe range of short is:%d to %d",d,e);
 l=pow(2,(sizeof(u)*8))-1;
 printf("\nThe range of unsigned short is:0 to %ld",l);
 d=pow(2,(sizeof(x)*8))/2;
 e=pow(2,(sizeof(x)*8))/2-1;
 printf("\nThe range of int is:%d to %d",d,e);
 l=pow(2,(sizeof(x)*8))/2-1;
 printf("\nThe range of unsigned int is:0 to %ld",e);
 n=pow(2,(sizeof(y)*8))/2;
 p=pow(2,(sizeof(y)*8))/2-1;
 printf("\nThe range of long is:%u to %u",n,p);
}

(ii) By printing appropriate values from standard header (limits.h )


#include<stdio.h>

#include<limits.h>
#include<float.h>
main()
{   
    printf("Minimum range of signed char variable: %d\n", SCHAR_MIN);
    printf("Maximum range of signed char variable: %d\n", SCHAR_MAX);
    printf("Maximum range of unsigned char variable: %u\n", UCHAR_MAX);
    printf("Minimum range of signed short variable: %d\n", SHRT_MIN);
    printf("Maximum range of signed short variable: %d\n", SHRT_MAX);
    printf("Maximum range of unsigned short variable: %u\n", USHRT_MAX);
    printf("Minimum range of int variable: %d\n", INT_MIN);
    printf("Maximum range of int variable: %d\n", INT_MAX);
    printf("Maximum range of unsigned int variable: %u\n", UINT_MAX);
    printf("Minimum range of signed long variable: %ld\n", LONG_MIN);
    printf("Maximum range of signed long variable: %ld\n", LONG_MAX);
    printf("Maximum range of unsigned long variable: %lu\n", ULONG_MAX);
    printf("Minimum range of long long variable: %lld\n", LLONG_MIN);
    printf("Maximum range of long long variable: %lld\n", LLONG_MAX);
    printf("Maximum range of unsigned long long variable: %llu\n\n", ULONG_LONG_MAX);
    printf("Minimum range of float variable: %e\n", FLT_MIN);
    printf("Maximum range of float variable: %e\n", FLT_MAX);
    printf("Minimum range of double variable: %e\n", DBL_MIN);
    printf("Maximum range of double variable: %e\n", DBL_MAX);
    printf("Minimum range of long double variable: %e\n", LDBL_MIN);
    printf("Maximum range of long double variable: %e\n", LDBL_MAX);
}

Comments

Popular posts from this blog

C-Programming with Record

C-Programming Programs Syllabus Click for full record  1.a) Write a C program to ask the user to enter one char ( Upper-Case letter) check  whether user  entered a Upper-case letter or not(by using relational and logical operators) and then if user has  entered a Upper-case letter  convert into a Lower-case letter? ( hint: Upper-case means capital letters,  use ASCII information to check for Upper-case and convert) b) Write a  C program to ask the user to enter two integers and apply all arithmetic operations on those  print the corresponding values?(hint : +,-,*,/,%)     c) Write a C program to Determine the ranges of char, short, int and long int variables both signed and  Unsigned   By using sizeof operator(ii) By printing appropriate values from standard header (limits.h )   2.a) Write a Program to Find the Roots of a Quadratic Equation using if else and Switch statements. b) Write a Program which Gener...

OOPS CPP Program-14

14. Write a program to find transpose of a given matrix of mxn size using unary operator overloading #include<iostream> using namespace std; class matrix {         int x[5][5],m,n; public:         matrix(){ }         matrix(int a,int b)         {                m=a;n=b;         }         void get();         void put();         matrix operator !(); }; void matrix::get() {         int i,j;         cout<<"\n Enter a matrix of order"<<m<<"x"<<n<<"\n";                for(i=0;i<m;i++)                    for(j=0;j<n;j++)                        ...

OOPS CPP Program-15

15. Write a program to concatenate one string to another using binary operator overloading. #include<iostream> #include<string.h> using namespace std; class str  {         char *st; public:         str(int len, char *s)         {                  int l=strlen(s);                st= new char[l];                st=s;          }         str()         {         }         void put();         str operator +(str); }; str str :: operator +(str s)  {  /*str abc; abc.st=strcat(st, s.st); return abc;*/         st=strcat(st, s.st);         return *this; } void str :: put() {   cout<<...