Ch4_11 - cout<<"Absolute...

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

View Full Document Right Arrow Icon
#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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

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

This note was uploaded on 03/20/2011 for the course CS 2 taught by Professor Barkeshli during the Spring '11 term at Pasadena City College.

Page1 / 2

Ch4_11 - cout&amp;amp;lt;&amp;amp;lt;&amp;amp;quot;Absolute...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online