Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // basic input output
- //#pragma warning(disable: 4996) ////same use as below. for integer input to disable warnings/issues.
- #define _CRT_SECURE_NO_WARNINGS
- /* Function for abs value */
- int doSomeMath(int toDetermine) // declared as type int to return, int is used for input
- {
- if (toDetermine < 0) // negative integer argument
- {
- return(toDetermine * -1);
- }
- else if (toDetermine > 0) // positive integer argument
- {
- return(toDetermine);
- }
- else // zero argument
- {
- return(0);
- }
- }
- /* Main */
- void main() // declared as type void instead of int. this is okay because this function doesn't need to return a result
- {
- // variable for input, variable for output
- int userInt, userOut;
- // prompt the user
- printf("Please enter an integer: ");
- // get input from user
- scanf("%d", &userInt);
- // call the function
- userOut = doSomeMath(userInt);
- // print the results
- printf("\nThe absolute value of %d is %d\n\n", userInt, userOut);
- }
Add Comment
Please, Sign In to add comment