Issue: ★ ☆ ☆ ☆
I began my expertise writing profession at a pc e-book publishing home, CompuSoft. It’s not round, however I do recall ghost writing books such because the BASIC Handbook, which was an encyclopedia of the BASIC programming language. The primary command listed on this e-book was ABS
.
The ABS
command returns absolutely the worth of an integer, which is its optimistic worth: ABS(5)
is 5. ABS(-200)
is 200.
I’ve seen absolute values used when coping with exponentiation as some calculations lead to each optimistic and unfavourable values. No matter. Nonetheless, it’s simpler for me to elucidate the way to write a C program to calculate that absolute worth than it’s for me to grasp math.
Earlier than you protest, I do know that the C library hosts a slate of absolute worth capabilities. These depend upon the integer measurement:
abs() for int values
labs() for lengthy values
llabs() for lengthy lengthy values
Don’t use any of those capabilities in your answer to this train! As an alternative, your problem is to put in writing a program that prompts the consumer for an integer (int) worth and outputs its absolute worth.
Right here’s are some pattern runs of my answer:
Enter an integer: 5
Absolutely the worth is 5
Enter an integer: -200
Absolutely the worth is 200
This activity might not appear too troublesome (therefore just one star), however a quirk exists when returning the worth of some unfavourable integers. I share this quirk together with my answer, which I’ll submit in every week.