0% found this document useful (0 votes)
33 views

Review On Data Types

This document discusses common programming data types in C language - integer, float, and double float. It explains that integers can only store whole numbers, while float and double float can store numbers with fractional components. Double float is similar to float but uses more memory. The key difference is that integer divides whole numbers, while float and double float preserve fractional values in calculations. Declaring variables with the proper data type is important for accurate results.

Uploaded by

vincent baltazar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Review On Data Types

This document discusses common programming data types in C language - integer, float, and double float. It explains that integers can only store whole numbers, while float and double float can store numbers with fractional components. Double float is similar to float but uses more memory. The key difference is that integer divides whole numbers, while float and double float preserve fractional values in calculations. Declaring variables with the proper data type is important for accurate results.

Uploaded by

vincent baltazar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Good day students!

So what happens when we input a non-whole number


input?
This will be a short review/discussion on the common
programming data types in C language namely:  If tried this on your code you will notice that the
integer, float, double float. input that was actually stored in your x variable is
only the whole number part of your input.
We previously discussed all about variables which is a
name for a location in a memory. We also learned how What if we input a non-numerical input?
to name them. As the name suggests, the values or the
contents of the variables can change as the program  This will only produce a random number.
executes. There are instances that a number with a fractional
Variables can be used to store numbers, texts, and component would be required as an input to our code.
other types of data. (For this class we will only limit to For these cases, we use the float or double float data
numbers and texts) types.

In programming, whenever we use a variable we must What is the difference between these two?
declare it first in order to make use of them
 Double float is just float with larger memory.
#include<stdio.h>
Let’s try running this code:
main ()
#include<stdio.h>

{ main (void)

int x; {

} float x;

printf(“Enter value for x:”);


For the code above, we just declared the variable x as
data type integer scanf(“%f”, &x);

We know from mathematics that integers are numbers


that can be written without a fractional component. In printf(“The value of x is: %f”, x);
other words, integers are whole numbers. Let’s try
}
coding this one.
If we want to use double float, in declaring just change
#include<stdio.h>
float to double. In accessing the variable, change
main (void) %f to %lf.
{
So how are these things important? For example given
int x; this code snippet,

printf(“Enter value for x:”); int x, y;

scanf(“%i”, &x); float z;

a = x / y + z;

printf(“The value of x is: %i”, x); Assume the inputs x = 1.5, y = 2.3, and z = 1.6.
} Using a calculator, the value assigned to variable a
would be 2.252.
(Type out the code in your compilers, do not copy +
paste.) However when we implement this code, the actual
value of variable a will be 2.1. This is because of the
Try running this code and then enter numerical inputs.
declared data types of the variables. I hope this is clear
Your output will be the same as your input as long as it
to you guys since we will encounter more math
is a whole number numerical value.
problems as we go on. Thanks.

You might also like