Lab 1 Intro Linux
Lab 1 Intro Linux
LAB 1
INTRODUCTION TO LINUX ENVIRONMENT AND C
COMPILER
ANSWER
1
EKT 120 – Introduction to Computer Programming Laboratory Module
1. GETTING STARTED:
// Program Example 1
// This program displays message "Welcome to UniMAP”
#include <stdio.h>
int main()
{
printf("\nWelcome to UniMAP\n");
return 0;
}
1.3.2 Once finished, save the program file or also known as the source file.
1.5.3 If you have found your file, use the command “gcc” to compile the
program “welcome.c”
gcc welcome.c
2
EKT 120 – Introduction to Computer Programming Laboratory Module
1.5.4 You can also compile the program and specify the output file (the
executable file) name together with the compile command. This is to
specify or named your binary file related to your program.
OR
Note: use the –o parameter to specify the output file, followed the
filename that you want to specify.
1.6.2 To run the default output (or binary) file, type: ./a.out
Note: the “./” to specify the binary file is in the current directory.
OR
Welcome to UniMAP
CONGRATULATIONS…!!!! You are now able to write and run your first program
successfully.
3
EKT 120 – Introduction to Computer Programming Laboratory Module
2. TASKS
Now you have learned to compile a simple C program, try to answer the following
questions:
2.3 Type, compile and run this program, correct any error(s) you may find and rewrite
the program.
main( )
{printf (“There is no class tomorrow” ); }
2.4 Determine and correct any error(s) you may find in the following command.
ma in() PRINTF *, („What is wrong?‟);
main()
{
printf (“What is wrong?”);
}
4
EKT 120 – Introduction to Computer Programming Laboratory Module
#include <stdio.h>
void main (void)
{
int dA;
float fB;
A = 2;
B = 3.0;
printf(“Learning Basic Structure of C Language”);
printf(“dA + fB = %f”, dA+fB);
}
a. Compile the above program and write down the comment given on the screen
after compiling.
refer to screen..
e. Correct the program so that the output looks presentable. Describe the changes
you have done and the output of the program.
5
EKT 120 – Introduction to Computer Programming Laboratory Module
refer to screen..
g. Explain the program in your own word and describe the command from top until
end of the program.