HP C A.06.05 Reference Manual
Expressions and Operators
Relational Operators (>, >=, <, ==, !=)
Chapter 5130
Example 5-3 C’s Relational Operators in Action
/* Program name is "relational_example". This program
* does some mathematical calculations and shows
* C's relational operators in action.
*/
#include <stdio.h>
int main(void)
{
int num, i;
printf("\n");
num = 5;
printf("The number is: %d\n", num);
for (i = 0; i <= 2; i++)
{
if (num < 25)
{
num *= num;
printf("The number squared is: %d\n", num);
}
else if (num == 25) {
num *= 2;
printf("Then, when you double that, you get: %d\n", num);
}
else if (num > 25)
{
num -= 45;
printf("And when you subtract 45, you're back where ");
printf("you started at: %d\n", num);
} /* end if */
} /* end for */
if (num != 5)
printf("The programmer made an error in setting up this \
example\n");
}
If you execute this program, you get the following output:
The number is: 5
The number squared is: 25
Then, when you double that, you get: 50
And when you subtract 45, you're back where you started at: 5