Tuesday, August 30, 2011

Separate Integer from a Decimal Number

Problem: Separate the integer part from a decimal number.

1. Prompt for a number.
2. Assign the number to a variable with ‘int’ data type.
3. There you go ;)

Source Code:
using namespace::std;
int main (void)
    double num;
    int integer;
    cout<<"Enter a decimal number: ";
    integer=num;        //an int can only save the integer part
    cout<<"Integer part of "<<num<<" is "<<integer;
    return 0;

This is a little trick I use to separate integers. Do tell me if you have any other ideas.

0 response(s):

Respond to this Post

Your participation is appriciated...