// program to understand type conversion
#include <iostream>
#include<stdlib.h> // to handle system("cls")
using namespace std;
int main()
{
system("cls");
int a;
int b;
float result;
cout<<"a and b="<<endl;
cin>>a>>b; //multiple inputs using >> operator called 'extraction' or 'get from' operator. 'cin' is an object.
result=(a*b)/2; // type casting takes place. It is implicit.
cout<<"implicit result ="<<result<<endl;// gives result 8 if we input 1 and 17.
result=float(a*b)/2; // type casting takes place (Explicit).
cout << "explicit result=" <<result<< endl;//gives result= 8.5 if we input 1 and 17
return 0;
}
#include <iostream>
#include<stdlib.h> // to handle system("cls")
using namespace std;
int main()
{
system("cls");
int a;
int b;
float result;
cout<<"a and b="<<endl;
cin>>a>>b; //multiple inputs using >> operator called 'extraction' or 'get from' operator. 'cin' is an object.
result=(a*b)/2; // type casting takes place. It is implicit.
cout<<"implicit result ="<<result<<endl;// gives result 8 if we input 1 and 17.
result=float(a*b)/2; // type casting takes place (Explicit).
cout << "explicit result=" <<result<< endl;//gives result= 8.5 if we input 1 and 17
return 0;
}
No comments:
Post a Comment