2. Write a simple program that converts one given data type to another using auto conversion and casting. Take the values form standard input.
#include<stdio.h>
void main()
{
int x = 10,sum=0; // integer x
char y = 'a'; // character Y
float z;
double w=1.2;
clrscr();
// y implicitly converted to int. ASCII
// value of 'a' is 97
x = x + y;
// x is implicitly converted to float
z = x + 1.0;
printf("\n Integer(implicit:char to Int) Value:x = %d",x);
printf("\n Float value(implicit:Int to Float) :z = %f", z);
// Explicit conversion from double to int
sum = (int)w + 1;
printf("\n sum (Exlicit:double to integer)= %d", sum);
getch();
}
OUTPUT:
Integer(implicit:char to Int) Value:x = 107
Float value(implicit:Int to Float) :z = 108.000000
sum (Exlicit:double to integer)= 2
Comments
Post a Comment