100% found this document useful (1 vote)
137 views

Lab 3 Introduction To C Programming: EKT 120 - Computer Programming Laboratory Module

This document outlines tasks for Lab 3 on introduction to C programming. It includes objectives like applying basic C rules, using printf and scanf functions, and working with fundamental data types. It provides examples of declaring different data types like characters, strings, integers and floating point numbers. It also gives tasks to write programs that calculate the product of integers, area of a circle, resistance values, separate digits of a number, and calculate distance and temperature using formulas. Pseudo code and flowcharts are required to be provided for the programs.

Uploaded by

Zainal Safwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
137 views

Lab 3 Introduction To C Programming: EKT 120 - Computer Programming Laboratory Module

This document outlines tasks for Lab 3 on introduction to C programming. It includes objectives like applying basic C rules, using printf and scanf functions, and working with fundamental data types. It provides examples of declaring different data types like characters, strings, integers and floating point numbers. It also gives tasks to write programs that calculate the product of integers, area of a circle, resistance values, separate digits of a number, and calculate distance and temperature using formulas. Pseudo code and flowcharts are required to be provided for the programs.

Uploaded by

Zainal Safwan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

EKT 120 Computer Programming

Laboratory Module

LAB 3
INTRODUCTION TO C PROGRAMMING

School of Computer and Communication Engineering


Universiti Malaysia Perlis

EKT 120 Computer Programming

Laboratory Module

1. OBJECTIVES:
1.1 To be able to apply basic rules and structures of C in writing a simple program.
1.2 To be able to use printf and scanf functions to display output and read input in a
program.
1.3 To become familiar with fundamental data types.
1.4 To be able to name, declare, assign and print values of variables used in
program.

2. TASKS:
2.1 What data types would you use to hold the following data and write C statements to
declare them all.
a. customer initial
Data type:
Declaration:
b. customer name
Data type:
Declaration:
c. your house number
Data type:
Declaration:
d. price
Data type:
Declaration:
e. car registration
Data type:
Declaration:
f.

time
Data type:
Declaration:

g. 6 digit number
Data type:
Declaration:

EKT 120 Computer Programming

Laboratory Module

2.2 Write a statement (or comment) to accomplish each of the following:


a.

State that a program will calculate the product of three integers.

b.

Define the variables x, y, z and result to be type int.

c.

Prompt the user to enter three integers.

d.

Read three integers from the keyboard and store them in the variables x, y and
z.

e.

Compute the product of the three integers contained in variables x, y and z and
assign the answer to the variable result.

f.

Print The product is followed by the value of the integer variable result.

2.3 Using the statements you wrote in Task 2.2, write a complete program that
calculates the product of three integers.

EKT 120 Computer Programming

Laboratory Module

2.4 Write a program that calculates marked area of the circle, given input from the user
r1 and r2.

r2

r1

a.

Write down the pseudo code and flowchart for the program:

b.

Write your program based on pseudo code and flowchart in (a):

EKT 120 Computer Programming

Laboratory Module

2.5 Write a program to find the equivalent series and parallel resistance for 3 resistor
values. Your program should scan the 3 resistor values and then compute the
equivalent series and parallel resistance for all 3 resistors. For example, if the 3
resistor values are r1=100, r2=200 and r3=300 ohms, respectively, their equivalent
series resistance is r1 + r2 + r3 = 100 + 200 + 300 = 600 ohms and their equivalent
parallel resistance = 1 / [1/r1 + 1/r2 + 1/r3] = 1/[0.01+0.005+0.0033] = 54.55 ohms.

a.

Write down the pseudo code and flowchart for the program:

b.

Write your program based on pseudo code and flowchart in (a):

EKT 120 Computer Programming

Laboratory Module

2.6 Write a program that inputs one five-digit number, separates the number into its
individual digits and prints separated from one another by three spaces each.[Hint :
Use combinations of integer division and the remainder operation.] For example, if
the user types in 42139, the program should print:
Sample Output:
Enter value : 42139
Answer :
4
2
1

a.

Write down the pseudo code and flowchart for the program:

b.

Write your program based on pseudo code and flowchart in (a):

EKT 120 Computer Programming

Laboratory Module

Additional Exercises:
2.7 Write a program to calculate the distance travel using the given formula below:
S = vt + at2
In your program ask user to input through keyboard the value of:
v = initial velocity
a = acceleration
t = time of travel
a.

Write down the pseudo code and flowchart for the program:

b.

Write your program based on pseudo code and flowchart in (a):

EKT 120 Computer Programming

Laboratory Module

2.8 Write a program to take a depth (in kilometers) inside the earth as input data;
compute and print the temperature at this depth in degrees Celsius and degrees
Fahrenheit.
Data Requirements
Problem Input
double dDepth

/*depth in km*/

Problem Outputs
double cCelcius
double dFahr

/*temperature in degrees Cescius*/


/*temperature in degrees Fahrenheit*/

Relevant Formulas
Celcius = 10 (depth) + 20
/*Celsius temperature at depth in km*/
Fahrenheit = 1.8 (Celsius) + 32;
a.

Write down the pseudo code and flowchart for the program:

b.

Write your program based on pseudo code and flowchart in (a):

You might also like