Tuesday, August 30, 2011

Separate Integer from a Decimal Number

Problem: Separate the integer part from a decimal number.


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

Source Code:
#include<iostream>
#include<conio.h>
using namespace::std;
int main (void)
{
    double num;
    int integer;
    cout<<"Enter a decimal number: ";
    cin>>num;
    integer=num;        //an int can only save the integer part
    cout<<"Integer part of "<<num<<" is "<<integer;
    getch();
    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...