0% found this document useful (0 votes)
6 views22 pages

lab0

The document provides an introduction to the CS19003 Programming and Data Structures Laboratory at IIT Kharagpur, detailing course logistics, lab schedules, and evaluation criteria. It outlines mandatory attendance, rules against plagiarism, and the use of C programming language for assignments. Additionally, it includes instructions for creating a Moodle account, submitting assignments, and examples of basic C programs.

Uploaded by

Arya Sarkar
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)
6 views22 pages

lab0

The document provides an introduction to the CS19003 Programming and Data Structures Laboratory at IIT Kharagpur, detailing course logistics, lab schedules, and evaluation criteria. It outlines mandatory attendance, rules against plagiarism, and the use of C programming language for assignments. Additionally, it includes instructions for creating a Moodle account, submitting assignments, and examples of basic C programs.

Uploaded by

Arya Sarkar
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/ 22

CS19003 : Programming and Data Structures

Laboratory (Section 4)

Lab0: Introduction

Department of Computer Science & Engineering


Indian Institute of Technology Kharagpur

January 6, 2025

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
1 / 22
Course Details: contact

Lab timing: Mondays 10 AM - 1 PM


Instructors:
▶ Prof. Palash Dey, Prof. Ayan Chaudhury, Prof. Debaditya Roy
▶ Email: {palash.dey, ayanc, debaditya}@cse.iitkgp.ac.in
Teaching Assistants:
▶ Koustav De ([email protected])
▶ Rahul Barman ([email protected])
▶ Sumit Dwivedi ([email protected])
▶ Khan Rohaan Qadeer Rakiya ([email protected])
▶ Lalita Purohit ([email protected])
▶ Bankar Akash Vijay ([email protected])
▶ Rishav Banerjee ([email protected])
▶ Megha Dilip Kumarsingh Manju
([email protected])
▶ Harsh Yadav ([email protected])
▶ Surajit Halder ([email protected])
▶ Pattani Akash Kamleshbhai ([email protected])
(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary
(Section6,4)
2025
Lab0: Introduction
2 / 22
Course Details: CSE Moodle access

All the course materials and assignment submission will be through


CSE Moodle page:
https://moodlecse.iitkgp.ac.in/moodle/login/index.php

Note: CSE Moodle is different from Institute Moodle


Creating account in Moodle:
▶ Follow the steps in the webpage
▶ Make sure that your name appears exactly same as you used it for your
admission in IIT
▶ After creating the account, use your roll number as your ID in Moodle
(THIS IS MANDATORY)
▶ Do not use lowercase letter or extra space in your roll number

Enrolling in PDS lab Section 4:


▶ Select the course “PDS Lab - Sec 4”
▶ Enrollment key: “Stud$PDSL4”

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
3 / 22
Course Details: weekly lab sessions

Rules of the game (we expect discipline and fair-play from you!)
▶ Attendance: Mandatory to get marks in each lab
▶ Plagiarism: Strict Penalty (sharing & copying both)
▶ Integrity: We have faith and full trust on you!

Some important rules


▶ Your absence will put zero in that lab’s mark (except valid medical
certificate from BCRTH)
▶ It is your responsibility to submit the correct file. No excuse will be
entertained (e.g. “I had made a mistake, you can check the timestamp
in my machine”; “I have accidentally deleted the file”, etc.)

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
4 / 22
Lab Schedule, Tests and Evaluations (TENTATIVE)

Lab Schedule:
▶ 06-Jan, 13-Jan, 20-Jan, 27-Jan, 03-Feb, 10-Feb, 17-Feb, 24-Feb,
03-Mar, 10-Mar, 17-Mar, 24-Mar, 31-Mar, 07-Apr, 14-Apr
(Midsem, Holiday)

Regular Evaluation:
▶ There will be approximately 11 regular labs
▶ Total weightage of 40% including all labs

Tests:
▶ There will be 2 lab tests
⋆ 10-Feb (tentative)
⋆ 07-April (tentative)
▶ Each test will have 30% weightage (so total 60% from lab tests)

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
5 / 22
What will happen in Lab Sessions everyday?

First 15 minutes of the lab will be short tutorial & explanation of the
assignments

Each lab will have approximately 2-3 programming assignments


▶ Will cover the topic of previous week’s theory class
▶ Questions will have various difficulty levels

Role of TAs
▶ Will help you if you get stuck, or having trouble in understanding
▶ But they will not tell you the solution

You have to submit via Moodle only within 1 PM

Appeal of marks
▶ Has to be done within one week of releasing the marks
▶ Talk to your marking TA first. If you still have concerns, then talk to us

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
6 / 22
How do you tackle the lab assignments everyday?

The only recipe to do good programs is to practice more and more

After getting the problem statement for an assignment, try to read it


thoroughly, categorize and separate out small subgoals and design
them to link each other to produce the overall goal

Every time you complete small intermediate objectives, try to print


and check whether that subgoal is properly achieved. Then, move on
to the next subgoal step-wise to complete the problem

Do not get tense if you are running out of time and still couldn’t solve
the problems!
▶ You will get Partial Marks for your efforts even if the program is not
fully finished or correct

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
7 / 22
Lab topics (Tentative)
We will cover the following topics in the labs tentatively
▶ Variables, assignments and I/O
▶ Conditional statements
▶ Loops and Iteration
▶ 1D array, string
▶ Function and Recursion
▶ Pointers & Dynamic memory allocation
▶ 2D array & structure
▶ Linked lists
▶ Stack & queue
▶ File handling

Programming language: C
(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary
(Section6,4)
2025
Lab0: Introduction
8 / 22
Textbooks and References

1 Brian W. Kernighan and Dennis M. Ritchie, “The C Programming


Language”, Prentice Hall of India, 1988.

2 E. Balaguruswamy, “Programming in ANSI C”, Tata McGraw-Hill,


2006.

3 Byron Gottfried, “Programming with C”, Tata McGraw-Hill, 2006.

4 Seymour Lipschutz, “Data Structures”, Schaum’s Outlines Series,


2017.

5 Ellis Horowitz, Satraj Sahni and Susan Anderson-Freed,


“Fundamentals of Data Structures in C”, W. H. Freeman and
Company, 1993.

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
9 / 22
Writing a C program
Steps to be followed:
1 Type the program in a file
2 Save the file with a name and .c extension
3 Compile
4 Run
C filenames MUST end with .c extension
Make sure to save the file every now and then (say 5 minutes) to
avoid losing work in case there is any serious problem

Which text editor to use?


Sublime text / Gedit

Which compiler?
We will use GCC compiler in Linux machine (same will be used for
checking the assignments by the TAs)

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
10 / 22
Our first C program

Source Code: file hello.c contains the following lines:


/***********************************
* Name : Your full name
* Roll No : 30CS10076
* Section : 4
* Lab No : 0
* Description : First C program
* Date : 06-Jan-2025
************************************/
#include <stdio.h>
int main()
{
/* Notice the indentation */
printf("Hello, beautiful world!\n");
return 0;
}

Output
Hello, beautiful world!

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
11 / 22
Our first program explanation

/*...*/: comment line not executed with program

#include <stdio.h>: tells the compiler to include information about


the standard I/O library

int: a data type of C indicating integers

main(): a special function. Every C program begins execution from


the first line in main

printf(): a library function that prints output

“Hello, beautiful world”: character string to be printed

\n: newline character

return: value returned from the function main()

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
12 / 22
How to compile and run??

Compilation
▶ Open a terminal in the same directory where you have saved the
program file
▶ You can also see the file(s) in the directory by typing ls command
▶ Type gcc ./hello.c in the terminal & press enter
▶ If the compilation is successful, an executable called a.out will be
created

Run
▶ Type the following command and press enter: ./a.out
▶ You will be able to see the output in the terminal itself

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
13 / 22
Our second example

This is also called the “short-circuit program”


#include <stdio.h>
int main ()
{
int n;
scanf("%d",&n);
printf("%d\n",n);
return 0;
}

This program accepts an integer as input and outputs the same


integer

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
14 / 22
Our third example

The “square finder”


#include <stdio.h>
int main ()
{
int n;
scanf("%d",&n);
printf("%d\n",n*n);
return 0;
}

This program takes an integer n as input and outputs the square n2


of n

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
15 / 22
Our fourth example

A “wrong reciprocal finder”


#include <stdio.h>
int main ()
{
int n;
scanf("%d",&n);
printf("%d\n",1/n);
return 0;
}

▶ The division 1/n is of integers (quotient)


▶ The format %d is for printing integers.

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
16 / 22
Our fourth example

A “correct reciprocal finder”


#include <stdio.h>
int main ()
{
int n;
scanf("%d",&n);
printf("%f\n",1.0/n);
return 0;
}

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
17 / 22
Tasks for today (not to be marked)
First create your CSE Moodle account at
https://moodlecse.iitkgp.ac.in
Enroll yourself into the course using student key Stud$PDSL4
▶ You should be able to see Assignment 0 is pending

Create a directory named Lab 0


▶ Write the program hello.c inside the directory
▶ Open a terminal in the directory
▶ Compile and run the code

If the program has executed correctly, submit the file hello.c via
Moodle
▶ What should be the file name?
⋆ Name your file as <roll no> <assignment no> <question no>
⋆ If your roll number is 14CS10001 and you are submitting
lab/assignment 3 question number (a), then name your file as
14CS10001 3 a.c
⋆ So your file number for this lab can be 30CS10076 0 a.c
(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary
(Section6,4)
2025
Lab0: Introduction
18 / 22
That’s all for today!

Questions?

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
19 / 22
Practice questions for homework

Write the following program, compile it and run. Change the


program, so that it prints it your name e.g. “My name is XXXXX”.
#include <stdio.h>
int main ()
{
printf("This is a test program to check printing. \n");
return 0;
}

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
20 / 22
Practice questions for homework

Write the following program, compile it and run. Change the


program, so that it assigns a fixed value to an integer, and reads
another integer from the user, and finally prints their sum.
#include <stdio.h>
int main ()
{
int x,y,z;
printf("Enter two integers \n");
scanf("%d%d",&x,&y);
z = x + y;
printf("Sum of %d and %d = %d \n", x, y, z);
return 0;
}

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
21 / 22
Practice questions for homework
Write the following program, compile it and run. Change the
program, by deleting the sentence “#include <math.h>” and see
what happens.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main ()
{
int n, i=3;
printf("Input the number \n");
scanf ("%d", &n);
while (i < sqrt(n)){
if (n % i == 0){
printf ("%d is not a prime \n", n);
exit(0);
}
i = i + 2;
}
printf ("%d is a prime \n", n);
return 0;
}

(CSE, IIT Kharagpur) CS19003 : Programming and Data Structures LaboratoryJanuary


(Section6,4)
2025
Lab0: Introduction
22 / 22

You might also like