0% found this document useful (0 votes)
45 views5 pages

Bic10204 Labactivity02 New

The document provides instructions for a lab activity on basic C programming. It includes: - Directions on how to set up an integrated development environment called DEV C++ and write, compile, and run a simple "Hello World" C program. - Examples of basic C program structure and syntax. - Exercises for students to write various C programs, including calculating values, getting user input, and converting a flowchart. Students are to document their code and output. The goal is for students to learn fundamental C programming concepts like program structure, compiling, and writing simple programs to perform calculations.

Uploaded by

Pro Ravin
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
0% found this document useful (0 votes)
45 views5 pages

Bic10204 Labactivity02 New

The document provides instructions for a lab activity on basic C programming. It includes: - Directions on how to set up an integrated development environment called DEV C++ and write, compile, and run a simple "Hello World" C program. - Examples of basic C program structure and syntax. - Exercises for students to write various C programs, including calculating values, getting user input, and converting a flowchart. Students are to document their code and output. The goal is for students to learn fundamental C programming concepts like program structure, compiling, and writing simple programs to perform calculations.

Uploaded by

Pro Ravin
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/ 5

FACULTY OF COMPUTER SCIENCE & INFO.

TECHNOLOGY
SEMESTER 1
BIC10204: ALGORITHM & PROGRAMMING 2023/2024
LAB ACTIVITY 02

Topics: CHAPTER 03-BASIC STRUCTURE OF PROGRAMMING

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]

Follow the instruction below:


1. Click mouse two times on DEV C++ icon on your computer desktop. You will see the screen
as below:

2. Click File→New to start writing a new program. Then, type as follows:

#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:

5. If the compilations succeed, select Execute→Run or F10 to run your program. A


working program should appear as 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.

7. References  Please refer to the following link:

i. How to write C Program with Dev C++


https://www.youtube.com/watch?v=WfGKYIWB1bU
ii. Introduction to C Programming with Dev C++: SimpleCLab
https://www.youtube.com/watch?v=uEI3-y9K7Z4

iii. Create your first C++ Program in Dev-C++ (Video 1)


https://www.youtube.com/watch?v=EWGxa-iLL8M

iv. Running and Testing Your First C++ Program (Video 2)


https://ww.youtube.com/watch?v=Xnc1Qbn2qrU

B - Writing a simple C programming code [1 hour & 30 min]

Basic structure of C:
// symbol for comment

#include <..> Header File

Preprocessor directive
int main()  Main Function
{
// identifiers;
Program body
// C statements;
}

Example:
#include <stdio.h>
int main()

{
char name[20];
identifier
int age;

printf(“Please enter your name : ”);


scanf(“%s”,&name);
printf(“Please enter your age : “); C
scanf(“%d”,&age); Statement
printf(“\nHello %s”, name);
printf(“\nYou are %d years old”, age);
}
Exercises:
 Write Lab Report by:
a) Type all the programming code, compile and run it. Then explain by analyse the
output (Q1-Q4).
b) Screen shot the coding & output (Q5-Q7)
1.
// Code is written by: < student name >

#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)

You might also like