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

C - Data Types

C - DATA TYPES
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C - Data Types

C - DATA TYPES
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

C DATA TYPES

OBJECTIVES:

1. To determine the required data types in solving problems.


2. To declare and assign values to variables.
3. To set the precision of data/information.

INTRODUCTION:

There are 4 basic data types in C:


– int - integers
– float – real (or floating point) numbers
– char – characters – a simple byte
– double – double-precision floating point

There are also three modifers: long, short and unsigned. In


effect, this gives us additional data types:
– unsigned – non-negative integers
– long – long integers
– short – short integers
– signed char – a one-byte signed integer
– unsigned long
– unsigned short
– long double

Syntax of a while loop

while (condition or logical expression )statement;


or
while (condition or logical expression ){
statements
}
REQUIREMENTS:

1. Modify the program below to display the output at the center of


the screen using escape specifiers. The program will convert the
temperature to Celsius from 300 to 0.

#include <stdio.h>
int main(void)
{
float fahr;
int lower, upper, step;
lower = 0;
upper = 300;
step = 20;
fahr = lower;
while (fahr <= upper) {
printf("%4.0f %6.1f\n", fahr, (5.0/9.0) * (fahr - 32.0));
fahr = fahr + step;
}

return(0);
}

2. Write a C - program to convert temperature from Fahrenheit


to Celsius degree. 
Test Data
Input a degree in Fahrenheit: 212
Expected Output :
212.0 degree Fahrenheit is equal to 100.0 in Celsius

NOTE:
The Fahrenheit scale is a temperature scale based on one
proposed in 1724 by physicist Daniel Gabriel Fahrenheit. It
uses the degree Fahrenheit (symbol: °F) as the unit.
The Celsius scale, previously known as the centigrade
scale, is a temperature scale used by the International
System of Units (SI). As an SI derived unit, it is used by all
countries in the world, except the U.S.

EQUATON: C/5 = (F – 32) / 9

3. Write a C - program that reads a number in inches, converts it


to meters. 

Test Data
Input a value for inch: 1000
Expected Output :
1000.0 inch is 25.4 meters

NOTE:
One inch is 0.0254 meter.
The inch is a unit of length in the (British) imperial and United
States customary systems of measurement now formally equal
to 1/36 yard but usually understood as 1/12 of a foot.

The meter is the base unit of length in some metric systems,


including the International System of Units (SI). The SI unit
symbol is m.

4. Write a C - program that reads an integer between 0 and 1000


and adds all the digits in the integer. 

Test Data
Input an integer between 0 and 1000: 565
Expected Output :
The sum of all digits in 565 is 16
NOTE:

An integer is a number that can be written without a fractional


component. For example, 23, 6, 0, and −1245 are integers, while
3.25, 7 1⁄2, and √3 are not.
Use % and / operators for this problem.

5. Write a C - program to convert minutes into a number of years


and days. 
Test Data
Input the number of minutes: 3456789
Expected Output :
3456789 minutes is approximately 6 years and 210 days

6. Write a C - program to compute body mass index (BMI). 


Test Data
Input weight in pounds: 452
Input height in inches: 72
Expected Output :
Body Mass Index is 61.30159143458721

NOTE:
BMI: The BMI is defined as the body mass divided by the square
of the body height, and is universally expressed in units of kg/m2,
resulting from mass in kilograms and height in metres.
BMI = Weight (kg) / Height (m2)

7. Write a C - program that accepts two integers from the user


and then prints the sum, the difference, the product, the average,
the distance (the difference between integer), the maximum (the
larger of the two integers), the minimum (smaller of the
two integers). 
Test Data
Input 1st integer: 25 
Input 2nd integer: 5
Expected Output :
Sum of two integers: 30
Difference of two integers: 20
Product of two integers: 125
Average of two integers: 15.00
Distance of two integers: 20
Max integer: 25 
Min integer: 5

You might also like