{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Ch4_11 - cout<<"Absolute value...

This preview shows pages 1–2. Sign up to view the full content.

#include <iostream.h> #include <conio.h> /************************************************** Name: Hung Truong Program: Ch4_11: ABS function in C++ Instructor: Mr. Barkeshli Purpose: Input: A number(Can be int, long, double, float) Output: Its absolute value **************************************************/ bool t=true; char c; int intnum; long longnum; double dblnum; float flnum; int abs(int num); long abs(long num); double abs(double num); float abs(float num); f main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(3); while (t==true) { cout<<"Enter a integer: ";cin>>intnum; cout<<"Absolute value of "<<intnum<<" is: "<<abs(intnum)<<endl; /***********/ cout<<"Enter a long: ";cin>>longnum;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<<"Absolute value of "<<longnum<<" is: "<<abs(longnum)<<endl; /***********/ cout<<"Enter a double: ";cin>>dblnum; cout<<"Absolute value of "<<dblnum<<" is: "<<abs(dblnum)<<endl; /***********/ cout<<"Enter a float: ";cin>>flnum; cout<<"Absolute value of "<<flnum<<" is: "<<abs(flnum)<<endl; /***********/ cout<<"You want to do it again(Y/N)? ";cin>>c; t=(c=='Y')|(c=='y'); } } int abs(int num) { if (num<0) num=-num; return num; } long abs(long num) { if (num<0) num=-num; return num; } double abs(double num) { if (num<0) num=-num; return num; } float abs(float num) { if (num<0) num=-num; return num; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Ch4_11 - cout<<"Absolute value...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online