1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gre4nikov [31]
3 years ago
15

How to solve a program that accepts a number as input and prints just the decimal portion

Computers and Technology
2 answers:
Mrrafil [7]3 years ago
7 0

Answer:

We can extract the decimal part of a number by casting the variable

Explanation:

Type casting is the process of  converting one datatype into another one. Basically, most of the languagues support type casting and we can use it in advantage to get the decimal part of a number.  Let assume you have a decimal number stored in your code, then let's do the following:

int integer_part = (int) float_number;

This is  a typlical way to cast a float number into a integer one. By doing so, you are getting the integer part of a float number while the decimal portion  is discarded.

Now you have a float number  and a variable with its integer part. Decimal portion is computed as follows:

float decimal_part = float_number - integer_part;

You can follow this scheme in any programming language with strong typing (datatypes  required to define a variable) and it will work ok.

lara31 [8.8K]3 years ago
3 0

<u>Answer:</u>

<em>There are 2 ways to do extract the decimal part: </em>

<u>Explanation:</u>

  • <em>First method using number </em>

<em>int main() { </em>

<em>  double doublenum = 24.535; </em>

<em>  int integerpart = (int)doublenum; </em>

<em>  double decimalpart = num - integerpart; </em>

<em>  printf(""Num = %f, integerpart = %d, decimalpart = %f\n"", doublenum, integerpart, decimalpart); </em>

<em>} </em>

  • <em>Second method using string: </em>

<em>#include <stdlib.h> </em>

<em>int main() </em>

<em>{ </em>

<em>    char* inStr = ""193.789"";          </em>

<em>    char* endptrvar;                      </em>

<em>    char* loc = strchr(inStr, '.'); </em>

<em>    long mantissaval = strtod(loc+1, endptrvar); </em>

<em>    long wholenum = strtod(inStr, endptrvar); </em>

<em>    printf(""whole: %d \n"", wholenum);      </em>

<em>    printf(""mantissa: %d"", mantissaval);   </em>

<em>} </em>

You might be interested in
Your program is going to compare the distinct salaries of two individuals for the last 5 years. If the salary for the two indivi
kirza4 [7]

In python:

i = 1

lst1 = ([])

lst2 = ([])

while i <= 5:

   person1 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   person2 = int(input("Enter the salary individual 1 got in year {}".format(i)))

   lst1.append(person1)

   lst2.append(person2)

   i += 1

if sum(lst1) > sum(lst2):

   print("Individual 1 has the highest salary")

else:

   print("Individual 2 has the highest salary")

This works correctly if the two individuals do not end up with the same salary overall.

4 0
2 years ago
What kind of device is a printer? output or input
ANEK [815]
A printer is output. :)
8 0
3 years ago
Free brainliest!?! &lt;3​
Sholpan [36]

Meee plzzzzz First!............

4 0
3 years ago
Read 2 more answers
write a C program the prints out the size of variables with the following C data types- int, long, unsigned, long long, double,
Anit [1.1K]

<u>C program for finding size of different data types</u>

#include <stdio.h>

//driver function

int main()

{

   int a;  //declaring a of type int

   float b; //declaring b of type float

   double c; //declaring c of type double

   char d; //declaring d of type char

   long e; //declaring e of type long

   long long f; //declaring f of type longlong

   unsigned g; //declaring g of type unsigned

   // Sizeof operator is used to evaluate the size of a variable

printf(" int data type contains: %lu bytes\n",sizeof(a));/*Finding size of int */

printf("float data type contains : %lu bytes\n",sizeof(b));/*Finding size of float */

printf("double data type contains: %lu bytes\n",sizeof(c));/*Finding size of double */

printf("char data type contains: %lu byte\n",sizeof(d));/*Finding size of char */

printf("long data type contains: %lu byte\n",sizeof(e));/*Finding size of long*/ printf("longlong data type contains: %lu byte\n",sizeof(f));/*Finding size of longlong */

printf("unsigned data type contains: %lu byte\n",sizeof(g)); /*Finding size of unsigned */

   return 0;

}

<u>Output</u>

int data type contains: 4 bytes

float data type contains : 4 bytes

double data type contains: 8 bytes

char data type contains: 1 byte

long data type contains: 8 byte

longlong data type contains: 8 byte

unsigned data type contains: 4 byte

4 0
3 years ago
What is the QOS model?
Andre45 [30]

Answer:

Quality Of Service

Explanation:

Technology that manages data traffic to reduce packet loss, latency and jitter on the network. QoS controls and manages network resources by setting priorities for specific types of data on the network.

5 0
3 years ago
Other questions:
  • Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respect
    8·1 answer
  • Does anyone know how to cancel a Pandora Free Trial Subscription? I need to cancel it by tomorrow. Please help!
    12·1 answer
  • Was the type writer the first part of the keyboard? ​
    8·1 answer
  • Why computer is known as data processing system?
    14·1 answer
  • _ models are non visual ways of communicating how someone thinks about something in the natural world
    12·1 answer
  • If you go over 255 in RGB by 1 does it reset to 0 or 1
    11·1 answer
  • What computer is designed to meet the computing needs of several people simultaneously in a small to medium-size business enviro
    5·1 answer
  • If you define a destructor, are you required to define an operator '=' and a copy constructor?
    9·1 answer
  • Add me on blizzard none of my friends play ow<br> NADERJABER#2530
    8·1 answer
  • A file named loan.html, write an HTML document that looks similar to figure 9-7 in the textbook. Write four functions with these
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!