Skip to content

Instantly share code, notes, and snippets.

@jtrent238
Created January 28, 2019 16:49
Show Gist options
  • Save jtrent238/dfb6f21836414b0546bcc6bf2b98c136 to your computer and use it in GitHub Desktop.
Save jtrent238/dfb6f21836414b0546bcc6bf2b98c136 to your computer and use it in GitHub Desktop.
// Programmer: Jonathan Trent Patterson & Brian Lorick
// Date: 1/28/2019
// Program Name: Split Double
// Chapter: Chapter 2 - Fundamentals
// Description: This Program gets user input as a decimal and splits it. It takes the number on the right and left of the decimal.
#define _CRT_SECURE_NO_WARNINGS // Disable warnings (and errors) when using non-secure versions of printf, scanf, strcpy, etc.
#include <stdio.h> // Needed for working with printf and scanf
int main(void)
{
// Constant and Variable Declarations
double decimalNum = 0.0;
int myNum = 0;
double decimalNum2 = 0.0;
// *** Your program goes here ***
printf("Enter a number that includes a decimal point: ");
scanf("%lf", &decimalNum);
myNum = ((float)decimalNum);
decimalNum2 = decimalNum - myNum;
printf("\n");//blank line
printf("The integer part of %lf is %d." "\n", decimalNum, myNum);
printf("The decimal part of %lf is %lf.", decimalNum, decimalNum2);
return 0;
} // end main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment