ii. Write a program in C++ with the following datatypes. Use the 3 different variables with the same data type. Explain the codes step by step.
a. int
b. float.
c. double. d. string. e. bool.
#include<iostream>
using namespace std;
int main(){
int a = 1;
string b = "Hello";
bool c = true;
float d = 12.78;
double e = 15.8776;
cout << "The variable a is an int and its values is : " << a << endl;
cout << "The variable b is a string and its values is : " << b << endl;
// This give an ouptut of 1 because true = 1 and false = 0 for boolean
cout << "The variable c is a boolean and its values is : " << c << endl;
cout << "The variable d is a float and its values is : " << d << endl;
cout << "The variable e is a double and its values is : " << e << endl;
return 0;
}
Comments
Leave a comment