Sample Program 1 :
/*
* Session_Two_Data_Types.c
*
* Created on: Nov 6, 2016
* Author: Admin
*/
* Session_Two_Data_Types.c
*
* Created on: Nov 6, 2016
* Author: Admin
*/
#include<stdio.h>
void main()
{
setbuf(stdout, NULL);
{
setbuf(stdout, NULL);
char alphabet = 'a';
int m1 =100;
int m2 = 90;
int m2 = 90;
float num1 = 1612345678.12345678;
float num2 = 13.34568789;
float num2 = 13.34568789;
/* Implicit conversion happens only between int and char without any assignment */
printf ("Value of variable alphabet as char %c",alphabet);
printf ("Value of variable alphabet as integer %d",alphabet);
printf ("Value of variable alphabet as hexadecimal %x \n",alphabet);
printf ("Value of variable alphabet as octa decimal %x \n",alphabet);
printf ("Value of variable alphabet as integer %d",alphabet);
printf ("Value of variable alphabet as hexadecimal %x \n",alphabet);
printf ("Value of variable alphabet as octa decimal %x \n",alphabet);
printf ("Marks 1 = %d , Marks 2 = %d \n",m1,m2);
printf ("Number 1 = %f , Number 2 = %f \n",num1,num2);
printf ("Number 1 = %6.3f , Number 2 = %5.1f \n",num1,num2);
/* In above statement 6 specifies how many digits we need to print totally, including "."
But if our value increases 6 digits, then the entire value withh be printed ignoring 6 in formatting string.
3 here is precision, this is to specify number of decimal degits we need to print.
Detailed discussion has been done in class */
printf ("Number 1 = %E , Number 2 = %5.1f",num1,num2);
}
Output :
Value of variable alphabet as char a
Value of variable alphabet as integer 97
Value of variable alphabet as hexadecimal 61
Value of variable alphabet as octa decimal 61
Marks 1 = 100 , Marks 2 = 90
Number 1 = 1612345728.000000 , Number 2 = 13.345688
Number 1 = 1612345728.000 , Number 2 = 13.3
Number 1 = 1.612346E+009 , Number 2 = 13.3
Value of variable alphabet as integer 97
Value of variable alphabet as hexadecimal 61
Value of variable alphabet as octa decimal 61
Marks 1 = 100 , Marks 2 = 90
Number 1 = 1612345728.000000 , Number 2 = 13.345688
Number 1 = 1612345728.000 , Number 2 = 13.3
Number 1 = 1.612346E+009 , Number 2 = 13.3
No comments:
Post a Comment