Bic10204 Labactivity02 New
Bic10204 Labactivity02 New
TECHNOLOGY
SEMESTER 1
BIC10204: ALGORITHM & PROGRAMMING 2023/2024
LAB ACTIVITY 02
Learning Outcome: At the end of this lab session, students are able to know:
• The Integrated Development Environment (IDE) for C software.
• The functions provided in DEV C++.
• How to write, compile and run a C program.
Duration: 2 Hours
Instructions:
i. Answer all questions (section B-exercises) and submit via author as a lab
report.
ii. Please use provided cover page & submission of lab report must be in .pdf
format. File name --> MatrikNO_LabActivity02.pdf
iii. DUE DATE: refer to AUTHOR
------------------------------------------------------------------------------------------------------------------------------------
A
- - How to compile and run a C program [30 min]
#include <stdio.h>
int main()
{
printf(“Welcome to the world of C programming”);
}
3. Upon completion, click File→Save As. At the File Name, type labactivity02.cpp and
click OK.
4. To compile the program, select Execute→Compile or click F9. If the program has no
error(s), you will see the compilation result similar as shown below:
6. It is advisable that you save your program before compiling. To ensure your program
is working, compile your program each time amendment is made.
Basic structure of C:
// symbol for comment
Preprocessor directive
int main() Main Function
{
// identifiers;
Program body
// C statements;
}
Example:
#include <stdio.h>
int main()
{
char name[20];
identifier
int age;
#include <stdio.h>
int main()
{
printf(“Welcome to FSKTM UTHM”);
}
2.
// Code is written by: < student name >
/* Code description: */
#include <stdio.h>
int main()
{
printf("\a");
printf("-------------------------------------------\n”);
printf("Welcome to UTHM");
printf("\n-----------------------------------------“);
printf("\n\tI love UTHM\n");
printf("I love Batu Pahat\n");
}
3.
// Code is written by: < student name
>
#include <stdio.h>
int main()
{
int number1, number2, number3;
int answer;
printf("Enter the first number:");
scanf("%d", &number1);
printf("\nEnter the second number’:
"); scanf("%d", &number2);
printf("\nEnter the third number: ");
scanf("%d", &number3);
answer = number1 + number2 - number3;
printf("\nThe answer is %d", answer);
}
4.
// Code is written by: < student name >
#include <stdio.h>
int main()
{
int radius, height; float volume;
printf("A program to calculate volume of a cone");
printf("\nEnter the radius : ");
scanf("%d", &radius);
printf("\nEnter the height : ");
scanf("%d", &height);
volume = 1.0 / 3.0 * 3.142 * (radius * radius) * height;
printf("\nThe volume of cone is = %f", volume);
}
5. Write a C program to print your full name, date of birth, mobile number and
home address.
6. Write a C program to compute the perimeter and area of a rectangle with a height
of 12m and width of 15m.
7. Convert the following flowchart into C programming code:
a) Find an area of a rectangle.
b) Calculate a simple interest, given by Simple Interest = Principal (P) xRate
(R) X Period in years (N)/100.
(b)
(a)