Você está na página 1de 16

UNIVERSITI TEKNOLOGI MARA

FACULTY OF ELECTRICAL ENGINEERING

ECE126
INTRODUCTION TO C PROGRAMMING
LABORATORY REPORT
Section A - filled up by student
Experiment No.

Title of Experiment

Date of Experiment

Lecturer

: WAN SUHAIFIZA BINTI W IBRAHIM

No
.

____/____/ 2015

Student Name

Student ID

Section B - filled up by lecturer


Received Date

____ / ____ / 2015

MARKS

____/ 10

Group

PART A
Input 1:

Output 1:

Input 2:

Output 2:

PART B
Input 1:

Output 1:

PART C
Input 1:

Output 1:

Input 2:

Output 2:

PART D
Input 1:

Output 1:

Input 2:

Output 2:

PART E
Input 1:

Output 1:

Input 2:

Output 2:

Input 3:

Output 3:

Input 4:

Output 4:

Input 5:

Output 5:

EXERCISE
Input 1:

Output 1:

DISCUSSION
In this laboratory, I learned the very basic of programming such as specifying the preprocessing directive (Example: #include <stdio.h>) which tells the compiler what to do before
executing the program. This is important as most function are contained within the library
specified in the pre-processing directive. Anything else is placed in the main body function.
In Part A, the printf is introduced. This function is included in <stdio.h> library thus it is
important to include it in the pre-processing directive. The printf function is used to display
the specified text or variable in the following format:
printf(Insert text here\n);
Any text can be inserted between the quote and it will be displayed exactly as it is written.
The \n is placed only if a new line is required. By cleverly arranging symbols and characters I
can create shape which is the purpose of Part B. In Part B, asterisks, spaces and new lines
were used to create a triangle.
In Part C, I learned how to declare and initialize a variable. When a variable is
declared and initialized, it is stored in the memory but it is not constant unless specified as
const. In programming, variables are important as it allows the program use formulas to
make calculation as an example. When using printf in conjunction with variables, a specific
format is required:
printf(The value of num1 is %d and num2 is %d\n, num1, num2);
The conversion specifier (%d) can be something else instead of d depending on the type of
value. %d is for interger, %f for floating number and %c for characters. For each conversion
specifier within the quote, a variable must be specified after the quote and comma with the
correct arrangement as shown above. It is also important to make sure that the variables
have been declared and initialized.
In Part D, scanf function is introduced. Unlike printf which displays the input, scanf
receives the input from user. This is important for programs which require data from users
instead of predetermined data. The format for scanf is shown below:
scanf(%d, &num1)
Again, the conversion specifier can be changed depending on what type of data is expected.
An important to take note here is that different from printf, only conversion specifiers are
allowed within the quote and an and sign (&) must be placed in front of the variable.
In Part E, arithmetic operators were introduced. The mentioned operators are addition
(+), subtraction (-), multiplication (*), division (/) and modulus (%). Division takes the result of
the division without decimals or remainder while modulus uses the remainder. An example of
their usage is shown below:
var1 = var2 + var3
In the example above, the value of var1 depends on the addition of the var2 and var3 which
can be predetermined or inputted by the user. The right hand side is always solved first and
only then it is applied to the left hand side.

CONCLUSION
In conclusion, I have learned how to specify the required pre-processing directive,
construct a main body function, declaring and initializing variables, using the function printf
and scanf and using the arithmetic operators to create formulas for calculation. By using all
these knowledge it is possible to create a simple program that can calculate the area of a
circle when given a radius as shown in the exercise.

Você também pode gostar