Practical-21
Write a cpp program for implementation of unary minus operator.
Introduction
Code
Practical-21.cpp
#include <iostream>
void main()
{
// Declare the variable a
int a;
// Read a value
std::cout << "Enter an integer: ";
std::cin >> a;
// Print the negative of a
std::cout << "The negative of " << a
<< " is " << -a;
return 0;
}
Output
Enter an integer: 5
The negative of 5 is -5