/* A program to use the same method to round both positive and negative numbers. Use -5.2, -5.8, 5.2, and 5.8 as test numbers. */ #include #include main () { /* The ceil() function takes a number to the next higher integer. This can be converted to rounding by first subtracting 0.5, as then, 5.2, say, will become 4.7, which the ceil function takes up to 5. */ int ans1, ans2, ans3, ans4; ans1 = ceil(-5.2 - .5); ans2 = ceil(-5.8 - .5); ans3 = ceil(5.2 - .5); ans4 = ceil(5.8 - .5); printf("If the rounding calculation works, the following values should\n"); printf("be -5, -6, 5 and 6:\n"); printf("%d %d %d %d\n", ans1, ans2, ans3, ans4); }