Lab1 2
Lab1 2
Objective: Getting familiar with the programming environment on the computer and writing the first program.
Suggested Experiments/Activities:
Tutorial 1: Problem-solving using Computers.
Lab1: Familiarization with programming environment
i. Basic Linux environment and its editors like Vi, Vim & Emacs etc.
ii. Exposure to Turbo C, gcc
iii. Writing simple programs using printf(), scanf()
Linux text editors can be used for editing text files, writing codes, updating user
instruction files, and more. A Linux system supports multiple text editors. A text editor
plays an important role while coding. So, it is important to select the best text editor. A
text editor should not only be simple but also functional and should be good to work
with.
Vi/VIM editor:
Vim editor is one of the most used and powerful command-line based editor of the Linux
system. By default, it is supported by most Linux distros. It has enhanced functionalities
of the old Unix Vi editor. It is a user-friendly editor and provides the same environment
for all the Linux distros. It is also termed as programmer's editor because most
programmers prefer Vi editor.
Vi editor has some special features such as Vi modes and syntax highlighting that
makes it powerful than other text editors. Generally, it has two modes:
Command Mode: The command mode allows us to perform actions on files. By default,
it starts in command mode. In this mode, all types of words are considered as
commands. We can execute commands in this mode.
Insert Mode: The insert mode allows to insert text on files. To switch from command
mode to insert mode, press the Esc key to exit from active mode and 'i' key.
To invoke the vi editor, execute the vi command with the file name as follows:
1. vi <file name>
Install Turbo C in your computer’s C Drive and follow the below shown commands to
open it.
Step2: Type cmd and hit Enter ; will open command prompt.
Step3: Now type cd\ and hit Enter (will takes you to root directory i.e C drive)
Step5: Type cd bin and hit Enter ( Now you are redirected to bin folder, a subfolder in tc)
Step6: Type TC and hit Enter (will open TC window now you can write edit and compile
your programs, through this command you are accessing an application called TC.exe )
How to Compile a C program using GCC
Step1: Go to Dashboard.
Step4: Now type vim <your filename with extension .c> Ex. vi prog1.c (This will create
a file prog1.c and opens it in a editor called vim)
Step5: Press i to get into insert mode and now you can type your program here.
Step6: After typing your program press escape to get out of insert mode and type ‘:wq’
without quotes and hit enter (This will make you to come out of vim editor by saving the
file)
Step7: Now type gcc <your file name with .c extension> and hit enter to compile your
file.
Step8: To execute your file type ./a.out and hit enter. This will run the file.
//Writing simple programs using printf(), scanf()
Program1:
#include<stdio.h>
int main()
printf(“Hello world\n”);
return 0;
Program2:
#include<stdio.h>
int main()
printf(“Name:N.Prasanna\n”);
printf(“D/o N.Suresh\n”);
printf(“Eluru\n W.G.Dt”);
printf(“Andhra Pradesh\n”);
return 0;
Program3:
#include<stdio.h>
int main()
{
char c;
int a;
float b;
scanf(“%c %d %f”,&c,&a,&b);
printf(“Character is %c\n,c);
printf(“Integer is %d\n”,a);
return 0;
WEEK 2
Objective: Getting familiar with how to formally describe a solution to a problem in a
series of finite steps both using textual notation and graphic notation.
Suggested Experiments /Activities:
Tutorial 2: Problem-solving using Algorithms and Flow charts.
Lab 1: Converting algorithms/flow charts into C Source code.
Developing the algorithms/flowcharts for the following sample programs
int main()
double temp1,temp2,temp3,temp4;
scanf("%lf", &temp1);
scanf("%lf", &temp3);
return 0;
Output: