Programming and Data Structure Laboratory (CS13002)

Similar documents
CS11002 Programming and Data Structures Spring Introduction

CS11001/CS11002 Programming and Data Structures Autumn/Spring Semesters. Introduction

CS19001/CS19002 Programming and Data Structures Lab Autumn/Spring Semester. Introduction. Abhijit Das. January 4, 2015

Practical Session 0 Introduction to Linux

Lecture 1. A. Sahu and S. V. Rao. Indian Institute of Technology Guwahati

Introduction to the Command line. Introduction to the command line. Introduction to the Command line. GNU/Linux at South Wales

Introduction to Linux. Fundamentals of Computer Science

PDS Lab Section 16 Autumn Tutorial 1. Unix Commands pwd The pwd command displays the full pathname of the current directory.

CSC111 Computer Science II

C++ Programming on Linux

Introduction to Algorithms and Programming I Lab. Exercises #1 Solution

3/13/2012. ESc101: Introduction to Computers and Programming Languages

Getting Started With UNIX Lab Exercises

Unit 10. Linux Operating System

Lab 1 Introduction to UNIX and C

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Introduction to Unix - Lab Exercise 0

1. The Mac Environment in Sierra Hall 1242

1. The Mac Environment in SIE 1222

Intermediate Programming, Spring Misha Kazhdan

Helpful Tips for Labs. CS140, Spring 2015

Introduction. Overview of 201 Lab and Linux Tutorials. Stef Nychka. September 10, Department of Computing Science University of Alberta

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

CENG393 Computer Networks Labwork 1

Computer System: An Overview

Lab Working with Linux Command Line

Unit 13. Linux Operating System Debugging Programs

Programming and Data Structure

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

Saint Louis University. Intro to Linux and C. CSCI 2400/ ECE 3217: Computer Architecture. Instructors: David Ferry

Linux hep.wisc.edu

COMP s1 Lecture 1

Temple University Computer Science Programming Under the Linux Operating System January 2017

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Lab 1 Introduction to UNIX and C

Introduction: The Unix shell and C programming

Beyond this course. Machine code. Readings: CP:AMA 2.1, 15.4

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

LAB 1 INTRODUCTION TO LINUX ENVIRONMENT AND C COMPILER

AMS 200: Working on Linux/Unix Machines

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Laboratory 1 Semester 1 11/12

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

CMSC 104 Lecture 2 by S Lupoli adapted by C Grasso

Embedded Systems Ch 3A Linux Development Environment

CS CS Tutorial 2 2 Winter 2018

Tutorial 1: Unix Basics

CMPUT 201: Practical Programming Methodology. Guohui Lin Department of Computing Science University of Alberta September 2018

Linux/Unix Filesystems

Using the Zoo Workstations

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Linux/Cygwin Practice Computer Architecture

Parallel Programming Pre-Assignment. Setting up the Software Environment

CS370 Operating Systems

Introduction to Supercomputing

1 Getting Started with Linux.

EKT332 COMPUTER NETWORK

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Introduction to Linux

The Unix Shell & Shell Scripts

Pointers and Arrays 1

Part I. Introduction to Linux

Compiling C/C++ programs

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

Hand-on Labs for Chapter 1 and Appendix A CSCE 212 Introduction to Computer Architecture, Spring

Introduction to C An overview of the programming language C, syntax, data types and input/output

CSE 391 Lecture 1. introduction to Linux/Unix environment

Basic Unix and Matlab Logging in from another Unix machine, e.g. ECS lab Dells

IEEE 754 Floating-Point Format

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

UNLV Computer Science Department CS 135 Lab Manual

DS: CS Computer Sc & Engg: IIT Kharagpur 1. roblem Set III. Goutam Biswas

15-122: Principles of Imperative Computation

Development Environment. ICLAB NCTU Institute of Electronics

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

For Dr Landau s PHYS8602 course

CS1600 Lab Assignment 1 Spring 2016 Due: Feb. 2, 2016 POINTS: 10

CS 3410 Intro to Unix, shell commands, etc... (slides from Hussam Abu-Libdeh and David Slater)

EECS2031 Software Tools

CMSC 201 Spring 2017 Lab 01 Hello World

CMSC 201 Spring 2018 Lab 01 Hello World

Introduction to C. Systems Programming Concepts

An Introduction to Unix

Exercise 1: Basic Tools

15213 Recitation Section C

Introduction to the UNIX command line

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

CSE 391 Lecture 1. introduction to Linux/Unix environment

CS 300. Data Structures

SU2017. LAB 1 (May 4/9) Introduction to C, Function Declaration vs. Definition, Basic I/O (scanf/printf, getchar/putchar)

Getting Started with UNIX

Introduction to Computing V - Linux and High-Performance Computing

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Linux Tutorial. Ken-ichi Nomura. 3 rd Magics Materials Software Workshop. Gaithersburg Marriott Washingtonian Center November 11-13, 2018

Linux Exercise. pwd answer: We call this directory (into which you get when you log in) your home directory.

EL2310 Scientific Programming

Transcription:

Programming and Data Structure Laboratory (CS13002) Dr. Sudeshna Sarkar Dr. Indranil Sengupta Dept. of Computer Science & Engg., IIT Kharagpur 1

Some Rules to be Followed Attendance is mandatory. Regular assignments must be done fully in the lab class. Each student must bring a C language book every day. If you face any problems catching up, draw the attention of one of the teachers. 2

Marks Distribution 40% of the PDS course marks is in the laboratory. Laboratory evaluation: Regular assignments : 25% Laboratory Test 1 : 20% Laboratory Test 2 : 25% Laboratory Test 3 : 30% 3

The Computing Environment PC with Pentium-4 processor Clock : 1.7 GHz Main Memory : 256 Mbytes Cache Memory (L2) : 256 Kbytes Hard Disk : 40 Gbytes 4

Operating System: Redhat Linux 7.3 / 8.0 Programming language: C Compiler : gcc Editor : emacs Window manager : KDE / Gnome 5

How to start and stop the machine? 6

How to start the machine? 1. Power on the PC (monitor first, then the main cabinet) 2. Wait until LILO boot: message comes on the screen. 3. Select the Linux option by pressing the arrow if necessary, and press Enter key. 4. Supply your login and password Login: cnn nn is the PC number (01, 02,..) Password: cnn 5. Click on the terminal icon to open a window (xterm). 7

Remember that.. It is possible to adjust the size of a window. It is possible to move a window to any position on the screen. You may create other windows from the first one by typing xterm & and then pressing the Enter key. A window must be active for you to type anything in it. To make a window active, move the mouse pointer to the upper horizontal bar of window, and press the left button of the mouse. 8

How to Power Off the Machine? 1. Close all windows. 2. Logout from the window manager. This leaves you again in the login console. 3. Select the Shutdown option. Wait till the machine completely shuts down. 4. Switch off the VDU (power of the main cabinet gets switched off automatically). 9

Steps in Running a Program A C program written on paper Emacs Editor A file on disk, say, first.c The executable file, a.out C Compiler gcc Library 10

How to Start the emacs Editor Select a window and enter the command emacs & An emacs window is created. You can select the font size. You can now type in a program (shown later). To close the emacs window Select Files menu of emacs Select Exit Emacs 11

Write, Compile & Execute a C Program 1. Start the emacs editor. 2. Select Files menu, and then select the Open File menu. 3. In the bottom of the emacs window you will be asked to give the name of a file where your C program will be stored. Say, the file name is first.c 12

4. Type the following C program in the emacs window: /** This is my first program */ /** Write your name, roll number, and PC no. here */ #include <stdio.h> int main() { printf ( This is my first program\n ); } 5. Save the buffer as the named file (first.c) by again selecting Files menu, and then selecting Save Buffer. 13

6. To compile the C program, type the following in a separate window: cc first.c cc is the name of the C compiler. If the process ends without any message, the compilation is successful, and the translated executable module is a.out. 7. Run the program a.out./a.out The message flashes on the screen. Close the emacs window. 14

If the Program has an Error /** This is my first program */ /** Write your name, roll number, and PC no. here */ #include <stdio.h> int main( No closing ) { printf ( This is my first program\n ); } If this program is compiled, we get the message first.c: In function main : first.c:6: parse error before } Line number 15

How to correct the mistake? 1. Open the file first.c in emacs. 2. Identify the errors, and fix them. 3. Save the modified file (same name). 4. Compile it again (using gcc), to get the new executable file a.out, and then run it. 16

Some Linux Commands ls : Lists the directory contents. pwd : Show current working directory. rm : Remove files. cd : Change working directory. mkdir : Make directories. rmdir : Remove empty directories. cat : Create and display (short) files. cp : Copy files and directories. mv : Move / rename files. man : Display on-line manual pages. 17

Files and Directories 18

Practice Program 1 /* This is the first practice program File name : second.c */ #include <stdio.h> int main() { int n; /* Declare an integer variable */ scanf ( %d, &n); /* Read the value of n */ printf ( Sum of (0 +... + %d) = %d\n, n, n*(n+1)/2 ); } Program expects an input 19

Practice Program 2 /* To find the area of a circle File name: third.c */ #include <stdio.h> #include <math.h> int main() { float radius, area; printf ( \nenter the radius: ); scanf ( %f, &radius); area = 4.0 * atan(1.0) * radius * radius; printf ( \nradius = %f, CircleArea = %f\n, radius, area ); } Must compile with the command cc lm third.c 20

Getting Information Look at the course web site at: http://www.facweb.iitkgp.ernet.in/~pds using Mozilla (or any other browser). How to take print-outs? Details available in the above web site. 21