// type casting and integer division #include #include using namespace std; int n1, n2, n3, n4, n5, n6, n7; int main() { n1 = 100; // integer constant assigned to n1 n2 = 1.5; // implicit type casting (avoid!) n3 = (int) 1.5; // explicit type casting -> 1 n4 = (int) -1.5; // explicit type casting -> -1 n5 = 5/2; // integer division -> 2 (avoid unless needed!) n6 = (int) (5./2.); // floating point division & type casting -> 2 n7 = (int) (5./2.+0.5); // do 5./2.+0.5 & type casting -> 3 cout << n1 << ' ' << n2 << ' ' << n3 << ' '; cout << n4 << ' ' << n5 << ' ' << n6 << ' ' << n7 << endl; }