0% found this document useful (0 votes)
1 views32 pages

CS101 - L1 - Introduction to Computer Programming

CSO101 is a Computer Programming course taught by Aparajita Khan at IIT BHU, accommodating 180 students from Electrical Engineering and Engineering Physics. The course covers problem-solving, algorithms, programming languages, and focuses on learning C as a foundational language. Students are encouraged to engage with programming concepts through practical exercises and are advised to explore online C compilers before the next class.
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)
1 views32 pages

CS101 - L1 - Introduction to Computer Programming

CSO101 is a Computer Programming course taught by Aparajita Khan at IIT BHU, accommodating 180 students from Electrical Engineering and Engineering Physics. The course covers problem-solving, algorithms, programming languages, and focuses on learning C as a foundational language. Students are encouraged to engage with programming concepts through practical exercises and are advised to explore online C compilers before the next class.
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

CSO101 - Computer

Programming
Course Instructor – Aparajita Khan
Assistant Professor, CSE, IIT BHU
Email – [Link]@[Link]
Course Information
• 180 students, joint batch of
– Electrical Engineering [EEE]
– Engineering Physics [PHY]
• Total registrations: 760 (institute-wide)

• Lectures: 3 Hours per week (D&V GF 1B) Lab: 2 Hours per week
– Tuesday: 08:00 – 09:00 AM Monday : 02:30PM – 04:30 PM [EEE 1-70]
Wednesday: 04:30PM – 06:30 PM [EEE 71-145]
– Wednesday : 08:00 – 09:00 AM
– Friday: 08:00 – 09:00 AM

• Tutorials: 1 Hour per week (D&V GF 1B)


– Wednesday: 03:30PM – 04:30 PM (for interactive question solving)
Problem Solving
"All life is problem solving" – Karl Popper
• Problem solving is at the heart of human activities
– involves creativity, logic, persistence, and decision-making

Real-world Mathematical Computational


• Managing traffic • Proving a theorem (problems that can be solved using
congestion • Solving a system of computers)
• Allocating classrooms linear equations • Searching for a contact in your
across courses • Evaluating the limit phonebook
• Scheduling sports of a function • Sorting a list of names alphabetically
tournaments • Encrypting a message so only the
intended recipient can read it
• Detecting spam emails
The recipe for computational problems
• Algorithm: Step-by-step instructions to solve a problem
– Finite
– Clear/Unambiguous
• An algorithm is your recipe.
• Programming is the implementation/translation of the
algorithm into instructions a computer can follow.
– Programming is like cooking the recipe!

Good Read: [Link]


How Mom Cooks = How a Computer Program
works
Mom Computer
Define Dish Define Problem
Define Recipe Define Algorithm
Follow Recipe Write a Program
Taste and adjust Dry run and Debug
Serve the food Output of the program
What a computer exactly is/does
• A computer is an electronic device that can be
programmed to perform sequence of operations and
produces an output.

– Input -> Program (Logic) -> Output

• Modern computers are used to perform a wide range of


tasks (computations).
Stored Program Computer
• Type of computer architecture where
the program instructions and data both
are stored in the computer’s memory.

• In 1945, John von Neumann proposed


it.
– It is called as Von Neumann
Architecture.

• Before this idea, computers had to be


rewired physically or manually
reprogrammed for every new task.
– That was slow and inefficient.

Image Source: [Link]


Stored Program Computer
• Key Characteristics:
– Program in Memory: Instructions are stored like data in main
memory (RAM).
– Single Memory for Both – Same memory unit stores both
code and data.
– Sequential Execution – Instructions are fetched one by one
and executed.
– Control Unit Driven – Control unit fetches, decodes, and
executes instructions.
Input Unit
• Accepts data and instructions from user.

Image Source: [Link]


Central Processing Unit (CPU)
• Also called as the brain of the computer.
• It has
– Control Unit (CU)
• Directs the operation of the entire system.
• Manages how data moves between other units.
– Arithmetic Logic Unit (ALU)
• Performs all arithmetic and logical operations.
• Here the actual processing happens.

Image Source: [Link]


Arithmetic Logic Unit (ALU)
• It actually performs calculations and logical operations
on data.
• It takes input as data from registers, and control signals
from CU.
• Key responsibilities:
– Arithmetic operations: Add, Sub, …
– Logical operations: AND, OR, …
– Comparisons: Less than, More than, …
– ….
Memory Unit (MU)
• It stores:
– Input data
– Instructions (program)
– Intermediate results
– Final output before displaying

• Types: Primary Memory and Secondary Memory


– RAM: Random Access Memory [volatile]
– ROM: Read-only Memory [non-volatile stores
firmware like BIOS]
– Secondary memory – e.g. Hard Disk, SSD, CD, Pen
Drive

Image Source: [Link]


Output Unit
• Displays or outputs the final result.

• Devices: Monitor, Printer, Speakers.

Image Source: [Link]


When you are going to buy a computer
• CPU
– Look at number of cores, processor generation, clock speed (GHz),
• RAM
– More RAM = smoother multitasking
• Storage
– SSD (Solid State Drive): Fast but costlier
– HDD (hard Disk Drive): Slow but cheaper
• Dedicated GPU
– It is a special processor designed to handle graphics and high-end
computation.
– Use cases: Gaming, 3D Modelling, Machine & Deep Learning
What is Language?
• A language is a system of communication used to
communicate between two or more parties.
– English
– Hindi
– Marathi
– Bengali
– Telugu
– French
– German
– …..
What about computers?
• Computers also need a language to understand and execute
a program (instructions).
• But they don’t understand:
– English
– Hindi
– Marathi They need their own language
– Bengali – Machine Language.
– Telugu
– French
– German
– …..
Programming Languages
• So to make computer understand, and give a set of
instructions, we need programming languages.
– Low-Level
• Close to machine (binary): Machine code, Assembly Language

– High-Level
• Close to human understandable format: C, Python, Java
How Computers will then understand
• Computers only understand machine language.
• We write program in high-level language like C.
• So, we need a translator to convert human code to
machine code.

• Ways to translate code:


– Compiler: Translates the entire code once, before running.
– Interpreter: Translates code line by line, dusting execution.
What we learnt till now?
• There is something called program
– Which is a set of instructions, which takes input and gives output.
– But how to write a program?
Mom Computer
Define Dish Define Problem
Define Recipe Define Algorithm
Follow Recipe Write a Program
Taste and adjust Dry run and Debug
Serve the food Output of the program
Let’s define a small problem
• Find the largest of two numbers.
Define the algorithm
• What is an Algorithm?
– It is a step-by-step, clear and finite set of instructions, to solve
a specific problem.
Define the algorithm
• What is an Algorithm?
– It is a step-by-step, clear and finite set of instructions, to solve
a specific problem.

• Key Characteristics:
– Takes zero or more inputs
– Produces at least one output
– Each step is clear and unambiguous
– It must terminate after a finite number of steps
– All steps must be simple enough to be performed by the computer
Write the Algorithm
• Problem: Find the largest of two numbers.

• Algorithm
– Step 1: Start
– Step 2: Read two numbers A and B
– Step 3: If A > B, then output A
– Step 4: Else, output B
– Step 5: Stop
Now before writing the program
• We should write the pseudocode
Pseudocode
– high-level description of an algorithm's steps without getting bogged down in
syntactic details of programming languages.

1. Start
2. Input A, B
3. If A > B then
Print A
4. Else
Print B
5. End

• It is more structured than an algorithm and closer to code.


Here is the program (In C)!
Why learn Programming?
• Programming is not only for computer students/scientists –
it is a new way to solve problems and accelerate
discoveries.
– You will work with formulas and mathematical models.
– You will collect and process experimental data and simulate
real-world systems.
– You need to automate the tasks - here you need programming.
Which programming language to
learn?
• Goal is not to learn a particular programming language.

• Goal is to learn how to learn any programming language.


– Problem-solving
– Thinking in steps
– Debugging and Testing
– Breaking complex problems into small manageable ones
So lets choose the language carefully!

• We will learn “C Programming Language”

• Learning C is like learning Latin.


– You may not use Latin everyday, but it helps you learn
Spanish, French and Italian, much more easily.
So, lets choose the language carefully!

• We will learn “C Programming Language”

• It will teach us all the fundamentals, then other


languages will be quite easy to learn.
– Basic data structures
– Control flow in a program
– Memory management
Learning C helps learning other languages

Once we learn C, we can pick up:


– C++ (for object-oriented high-performance applications)

– Python (for machine learning, data science, deep learning)


– This you can learn by your own quickly or even parallelly!

– Java (for industry ready software development)

– R (for statistical computing)


Next Class
• So, we have set the context for “C Programming
Language”.
• Before next class, if possible, type online C compiler in
Google.
– Open anyone and type this and run and play with it,
Thanks!

Email – [Link]@[Link]
You can send me any email regarding this
course, please start the subject with CSO101 -

You might also like