ID1063: Introduction to
Programming (Lab-1)
J. Saketha Nath, Saurabh Kumar, Jyothi Vedurada
Dept of CSE
IIT Hyderabad
(1st August 2024)
How to Communicate (Language)?
Speaks
English
Speaks
English
Alex
Bob
2
How to Communicate (Language)?
Speaks
English
Speaks
English
Alex
Bob
• Speaks same language
• No problem
3
How to Communicate (Language)?
Speaks
English
Speaks
Chinese
Alex
Dong
• Speaks different language
4
How to Communicate (Language)?
Speaks
English
Speaks
Chinese
Alex
Translator
Dong
• Speaks different language
• Add translator. Problem is solved
5
How to Communicate (Language)?
Understand
machine code
Can write code
in C
Alex
C Compiler
Computer
• Write code in C
• Convert C code into machine code using C compiler
• Then execute
6
What We Need (Compiler)?
We know how to write program in C
❑Need C compiler to convert into machine code
❑Compiler can be
➢ Web based (Prutor)
▪
Compilation and execution happens on a server machine
▪ accessible through browser
➢ Native (GCC, Clang, Borland Turbo C, etc..)
▪ Compile and execute program locally in your machine
▪ Platform depended (Linux, Windows, Mac)
7
ITP-Monitor and Prutor
8
Install ITP-Monitor in Chrome
❑Download the ITP-Monitor from https://skmtr1.github.io/slides/ITP-
Monitor.zip
❑Uncompress the zip file and not down the location of uncompressed
folder
❑Open Chrome browser
❑Enter the chrome://extensions on URL bar of Chrome browser
❑Follow the steps as shown in upcoming slides
9
Install ITP-Monitor in Chrome
Step-1: Access chrome://extensions
Step-2: Enable developer
mode if disabled
Step-3: Click on
Load unpacked
10
Install ITP-Monitor in Chrome
Step-3: Select
ITP-Monitor
folder
Step-4: Click on
Select Folder
11
Install ITP-Monitor in Chrome
Monitor is
installed
12
Register Your Details With ITP-Monitor
Step-1: Click on
Extensions icon
13
Register Your Details With ITP-Monitor
Step-2: Click on
ITP Monitor
14
Register Your Details With ITP-Monitor
Step-3: Click on Edit
Details if these are
wrong/not available
15
Register Your Details With ITP-Monitor
Step-4: Fill details
Step-5: Save
16
Prutor Platform
17
Prutor
❑Set your password for Prutor
➢ Check email for password reset instructions (Notify us if not received)
❑Access Prutor
➢ Connect your machine with IITH WiFi or LAN
➢ https://prutor.cse.iith.ac.in/
➢ During Lab/Exam: Only accessible from the venue
➢ Can access from anywhere in IITH rest of the time.
18
Login
Your IITH email ID
(xxx@iith.ac.in)
19
Dashboard (Home Page)
1
2
4
5
6
7
3
20
Dashboard (Home Page) Description
1. On going Lab/Exam/Quiz
2. Statistics: No. of problem (not) submitted, scheduled events
3. Grade card that will show marks each event and problem
4. Click on it to start solving the problem
5. Can raise request to regrade questions
6. Problem assigned for practice purpose only
7. Write any arbitrary code for practice
21
Specific Problem (Lab/Exam)
Write your code here
Problem description
for Lab/Exam
22
File Menu
Only visible for
scratch pad
23
Run Menu (Compile, Execute, and Evaluate)
Not available
for scratchpad
24
Scratchpad
Organize your own
code for practice
Area to write code for
your own problem
25
Setting Up Native Compiler
Windows
Linux
Mac
26
GCC on Windows
❑Windows sub-subsystems for Linux (WSL)
➢ Only works on Windows 10 version 2004 and higher (Build 19041 and
higher)
➢ Installation instructions (https://learn.microsoft.com/enus/windows/wsl/install)
➢ Install GCC specific to Linux distribution (Ubuntu, RedHat, etc..)
▪ See GCC on Linux
❑Using Cygwin (https://cygwin.com/)
27
GCC on Linux
❑Ubuntu or Debian:
➢ sudo apt update
➢ sudo apt install build-essential
or
➢ sudo apt install gcc
❑RedHat:
➢ sudo yum group list
➢ sudo yum group install "Development Tools”
or
➢ sudo yum install gcc
28
GCC on Mac
❑Install homebrew (Instruction: https://brew.sh/)
❑After that
➢ brew update
➢ brew upgrade
➢ brew install gcc
29
Write, Compile and Execute
a Program
30
Basic Program: Print Hello World
hello.c
#include <stdio.h>
int main(){
char *str = "Hello World!\n";
printf("%s", str);
return 0;
}
Use any editor program to
write code, e.g., notepad,
notepad++, nano, etc..
compile
gcc hello.c
a.out
execute
Hello World!
./a.out
31
Lab-1 Questions
Four Questions
32
Q1: Hello World
❑Write a C program that prints "Hello World!" (including the quotation
mark) on that STDOUT console. Note that ‘ \” ' in the print command
can print the double quotation mark on STDOUT console.
33
Q2: Pattern Printing
❑Write a C program to print a flag pattern using "X" character. Note that
`\n' in the print command makes the text cursor move to the next line.
Your output must be the one below:
XXXXXX
XXXXX
XXXX
XXX
XX
X
XX
XXXX
XXXXX
XXXXXX
34
Q3: Escaper Characters
❑Write a C program that prints the following paragraph as it is:
Here is an example paragraph demonstrating escape characters in C:
Learning C programming requires understanding escape characters. A newline character \n
starts a new line, while a tab \t can be used for indentation.
A backslash \\ lets you include backslashes in your output.
If you need to include quotes, use double quotes \" or single quotes \' for precise output.
35
Q4: Pattern Printing 2
❑Write a C program to print a pyramid pattern using 1, 2, 3, and 4, as
shown below. Note that `\n' in the print command makes the text
cursor move to the next line. Your output must be the one below:
1
12
123
1234
36