Google
 
Webcprogramming.com




An Affiliate of AIHorizon




abs()

Prototype: int abs(int aNum);
Header File: stdlib.h (C) or cstdlib (C++)
Explanation: The abs function returns the absolute value of a number (makes it positive) as an integer.



Example:
//Program asks for user input of an integer
//It will convert it to positive if it was negative
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
  int aNum;
  cout<<"Enter a positive or negative integer";
  cin>>aNum;
  cout<<abs(aNum);
}
Other Functions


-----
Interested in advertising with us?
Please read our privacy policy.
Copyright © 1997-2005 Cprogramming.com. All rights reserved.
Designs