SlideShare a Scribd company logo
1 of 20
CSCI 101
First Program
Memory variables, input, disp, arithmetic
expressions, math functions
Overview
● Review: How to write a program?
● Substitution in mathematics & programming
● Building our first program
● Memory
● Getting input
● Displaying output
● Arithmetic expressions
● Sample programs
Substitution in mathematics & programming
● Software evolved first to serve solving
mathematical problems
● Therefore, it follows the main concepts of
evaluating expressions
● Substitution in mathematical expressions
works the same way in code
Substitution in mathematics & programming
𝑥 = 4
𝑦 = 𝑒 𝑥
● Solving the above mathematically by
substituting manually step by step:
𝑦 = 𝑒√4
𝑦 = 𝑒2
𝑦 = 2.7182
𝑦 = 7.38
Substitution in mathematics & programming
● In MATLAB, it is written as:
x = 4;
y = exp(sqrt(x));
● By substituting step by step:
1. First 4 is assigned to x
2. Then x is substituted for, y = exp(sqrt(4))
3. Function sqrt(4) is called which takes 4 as an input, gets
evaluated and returns back 2, now y = exp(2)
4. Function exp(2) is called which takes 2 as an input, gets
evaluated and returns back 7.38 which gets assigned to y
Exercise: x = 4; y = cos(exp(x/2-2)*pi)/sin(pi/2);
How to write a program?
1.Read the problem statement, and identify
–The input and its range
–The output
–The relationship between the input and the output (how
to compute the output) [Comprehend]
2.Write your thoughts as a sequence of steps. [Algorithm]
3.Convert these steps to Code. [Program]
4.Test your code and compare your program result against a
human result. [Testing]
Calculate area of a rectangle
(Problem  Algorithm)
How a computer can solve this problem?
I get the values of the height and the width from you and I store them in my
memory.
 Get height as h
Get width as w
Then I multiply them in my brain and store the result in my memory
 Calculate area = h*w
and inform you about the resultant value.
 display area
Calculate area of a rectangle
(Algorithm  Program)
1. Get height h
 h=input(‘enter height: ’);
2. Get width w
 w=input(‘enter width: ’);
3. Calculate area = h * w
 area = h * w;
4. Display area
 disp (area);
Memory
•Memory is divided into bytes
•Each byte has its own address
represented by binary numbers
•4 or 8 bytes form a memory
location to store integer or
floating (Ex 10.2345) numbers
•Software Programs uses letters
and decimal numbers to name
the memory location.
15
12
45
2
-3
4
x
y
sum
A
A1
numOfBus
Memory Location Name
(Variables)
•Variable: a named space for storing a value
radius
•Valid names start with a letter, can contain
digits.
•Use meaningful variable names.
•MATLAB is case sensitive (area and Area are different)
Xyz 3xyz x-y ab2cd a12345 myvar AbCdE1234?
Get input from user
h=input(‘enter height: ’);
Memory location
to store the input
Keyword to hold the
program execution to
get input from the keyboard
Message to the user
Write a Matlab statement to take the circle radius from the user and store it
in ‘R’.
>> enter height:
5h
?
5
Get an array from user
X=input(‘enter array elements: ’);
>> enter array elements: [4 5 2 6 8]
length(X): number of elements
To access the array elements use X(index)
Where index is an integer from 1 to length(X)
What is the value of: X(4)= X(6)=
4
5
2
6
8
X(1)
X(2)
X(3)
X(4)
X(5)
?
Display to Screen
disp(h);
Memory location
to display
Keyword to display
to the screen
>> 5
5
102
h
disp(a);
>> 102
a
Arithmetic Expressions
Operations
^ Exponentiation (5^2 is 25)
*, / Multiplication and division
+, - Addition and subtraction
Examples
x=4; y=3.5; z=2;
a= x +y – 5 / (3+z);
b=a + x / 2;
4
3.5
2
6.5
8.5
x
y
z
a
b
Operations are executed only one at a time according to their
precedence. We will study it further in future lectures
Calculate area of a rectangle
(Program and Testing)
h=input(‘enter height: ’);
w=input(‘enter width: ’);
area = h * w;
disp (area);
enter height: 5
enter width: 4
20
5
4
20
h
w
area
Calculate area of a circle
(Algorithm, Program, Testing)
1. Get radius r
2. Calculate area = pi*r^2
3. Display area
r=input(‘enter radius:’);
area =pi*r^2;
disp(area);
enter radius: 5
49.3480
5
49.3480
radius
area
Calculate number of buses to
transfer students (Algorithm)
1.Get number of students as numS
2.Get the bus capacity as busC
3.Calculate num of buses as
numB = numS/busC (round up)
4. Display numB
Calculate number of buses to
transfer students (Program)
numS=input(‘enter number of students:’);
busC=input(‘enter bus capacity:’);
numB = numS/busC;
disp(numB);
ceil(1.2) = 2 ceil round up to nearest integer
 numB = ceil(numS/busC);
If numS=60 and busC = 50 then numB = 60/50 = 1.2 ???
But it should be 2
Calculate number of dozens and
remainder (Algorithm)
1.Get a number as N
2.Calculate dozen = N/12 (no fraction)
3.Calculate the reminder (r) of dividing N by 12
4.Display dozen
5.Display r
Calculate number of dozens and
remainder (Program)
N=input(‘enter a number’);
dozen = N/12;
r = ??
disp(dozen);
disp(r);
fix(5.8) = 5 fix removes the fraction
rem(10,3) = 1 rem calculates the reminder of dividing 10 by 3
rem(100,2) = 0
 dozen = fix(N/12);
 r= rem(N,12);

More Related Content

What's hot

Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocksJothi Lakshmi
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchHema Kashyap
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
 
Assignment statements
Assignment statementsAssignment statements
Assignment statementsDivya Devan
 
Digital logic design1
Digital logic design1Digital logic design1
Digital logic design1jntuworld
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.comjonhson300
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comjonhson129
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALVivek Kumar Sinha
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2Animesh Chaturvedi
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solutionAnimesh Chaturvedi
 
maXbox starter68 machine learning VI
maXbox starter68 machine learning VImaXbox starter68 machine learning VI
maXbox starter68 machine learning VIMax Kleiner
 
Specialized indexing for NoSQL Databases like Accumulo and HBase
Specialized indexing for NoSQL Databases like Accumulo and HBaseSpecialized indexing for NoSQL Databases like Accumulo and HBase
Specialized indexing for NoSQL Databases like Accumulo and HBaseJim Klucar
 

What's hot (20)

Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
Lecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star searchLecture 21 problem reduction search ao star search
Lecture 21 problem reduction search ao star search
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
Iterative deepening search
Iterative deepening searchIterative deepening search
Iterative deepening search
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
Assignment statements
Assignment statementsAssignment statements
Assignment statements
 
Digital logic design1
Digital logic design1Digital logic design1
Digital logic design1
 
Array
ArrayArray
Array
 
GSP 215 Enhance teaching/tutorialrank.com
 GSP 215 Enhance teaching/tutorialrank.com GSP 215 Enhance teaching/tutorialrank.com
GSP 215 Enhance teaching/tutorialrank.com
 
GSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.comGSP 215 Inspiring Innovation/tutorialrank.com
GSP 215 Inspiring Innovation/tutorialrank.com
 
Programming with matlab session 1
Programming with matlab session 1Programming with matlab session 1
Programming with matlab session 1
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Code optimization
Code optimization Code optimization
Code optimization
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
PECCS 2014
PECCS 2014PECCS 2014
PECCS 2014
 
C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2C - Programming Assignment 1 and 2
C - Programming Assignment 1 and 2
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
maXbox starter68 machine learning VI
maXbox starter68 machine learning VImaXbox starter68 machine learning VI
maXbox starter68 machine learning VI
 
Specialized indexing for NoSQL Databases like Accumulo and HBase
Specialized indexing for NoSQL Databases like Accumulo and HBaseSpecialized indexing for NoSQL Databases like Accumulo and HBase
Specialized indexing for NoSQL Databases like Accumulo and HBase
 

Similar to Csci101 lect01 first_program

JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
Introduction to programming - class 3
Introduction to programming - class 3Introduction to programming - class 3
Introduction to programming - class 3Paul Brebner
 
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using HaskellFunctional Thursday
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
CSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow ChartsCSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow ChartsYhal Htet Aung
 
Support Vector Machines Simply
Support Vector Machines SimplySupport Vector Machines Simply
Support Vector Machines SimplyEmad Nabil
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialTo Sum It Up
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfssuserff72e4
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
Design and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptDesign and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptmoiza354
 

Similar to Csci101 lect01 first_program (20)

JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
c-programming
c-programmingc-programming
c-programming
 
Introduction to programming - class 3
Introduction to programming - class 3Introduction to programming - class 3
Introduction to programming - class 3
 
[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell[FLOLAC'14][scm] Functional Programming Using Haskell
[FLOLAC'14][scm] Functional Programming Using Haskell
 
R programmingmilano
R programmingmilanoR programmingmilano
R programmingmilano
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
CSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow ChartsCSC1100 - Chapter12 - Flow Charts
CSC1100 - Chapter12 - Flow Charts
 
Support Vector Machines Simply
Support Vector Machines SimplySupport Vector Machines Simply
Support Vector Machines Simply
 
Problem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study materialProblem solving using computers - Unit 1 - Study material
Problem solving using computers - Unit 1 - Study material
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
Mathematical Modeling With Maple
Mathematical Modeling With MapleMathematical Modeling With Maple
Mathematical Modeling With Maple
 
Lecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdfLecture1_computer vision-2023.pdf
Lecture1_computer vision-2023.pdf
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Design and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.pptDesign and Analysis of Algorithm Brute Force 1.ppt
Design and Analysis of Algorithm Brute Force 1.ppt
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Matlab1
Matlab1Matlab1
Matlab1
 
Get Fast C++ Homework Help
Get Fast C++ Homework HelpGet Fast C++ Homework Help
Get Fast C++ Homework Help
 
Ch3
Ch3Ch3
Ch3
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 

More from Elsayed Hemayed

14 cie552 camera_calibration
14 cie552 camera_calibration14 cie552 camera_calibration
14 cie552 camera_calibrationElsayed Hemayed
 
12 cie552 object_recognition
12 cie552 object_recognition12 cie552 object_recognition
12 cie552 object_recognitionElsayed Hemayed
 
11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift11 cie552 image_featuresii_sift
11 cie552 image_featuresii_siftElsayed Hemayed
 
10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner10 cie552 image_featuresii_corner
10 cie552 image_featuresii_cornerElsayed Hemayed
 
09 cie552 image_featuresi
09 cie552 image_featuresi09 cie552 image_featuresi
09 cie552 image_featuresiElsayed Hemayed
 
08 cie552 image_segmentation
08 cie552 image_segmentation08 cie552 image_segmentation
08 cie552 image_segmentationElsayed Hemayed
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicingElsayed Hemayed
 
06 cie552 image_manipulation
06 cie552 image_manipulation06 cie552 image_manipulation
06 cie552 image_manipulationElsayed Hemayed
 
05 cie552 image_enhancement
05 cie552 image_enhancement05 cie552 image_enhancement
05 cie552 image_enhancementElsayed Hemayed
 
04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequencyElsayed Hemayed
 
03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatialElsayed Hemayed
 
02 cie552 image_andcamera
02 cie552 image_andcamera02 cie552 image_andcamera
02 cie552 image_andcameraElsayed Hemayed
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionElsayed Hemayed
 
Csci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiCsci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiElsayed Hemayed
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeElsayed Hemayed
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programsElsayed Hemayed
 
Csci101 lect08a matlab_programs
Csci101 lect08a matlab_programsCsci101 lect08a matlab_programs
Csci101 lect08a matlab_programsElsayed Hemayed
 
Csci101 lect07 algorithms_ii
Csci101 lect07 algorithms_iiCsci101 lect07 algorithms_ii
Csci101 lect07 algorithms_iiElsayed Hemayed
 
Csci101 lect06 advanced_looping
Csci101 lect06 advanced_loopingCsci101 lect06 advanced_looping
Csci101 lect06 advanced_loopingElsayed Hemayed
 

More from Elsayed Hemayed (20)

14 cie552 camera_calibration
14 cie552 camera_calibration14 cie552 camera_calibration
14 cie552 camera_calibration
 
12 cie552 object_recognition
12 cie552 object_recognition12 cie552 object_recognition
12 cie552 object_recognition
 
11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift11 cie552 image_featuresii_sift
11 cie552 image_featuresii_sift
 
10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner10 cie552 image_featuresii_corner
10 cie552 image_featuresii_corner
 
09 cie552 image_featuresi
09 cie552 image_featuresi09 cie552 image_featuresi
09 cie552 image_featuresi
 
08 cie552 image_segmentation
08 cie552 image_segmentation08 cie552 image_segmentation
08 cie552 image_segmentation
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicing
 
06 cie552 image_manipulation
06 cie552 image_manipulation06 cie552 image_manipulation
06 cie552 image_manipulation
 
05 cie552 image_enhancement
05 cie552 image_enhancement05 cie552 image_enhancement
05 cie552 image_enhancement
 
04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency04 cie552 image_filtering_frequency
04 cie552 image_filtering_frequency
 
03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial03 cie552 image_filtering_spatial
03 cie552 image_filtering_spatial
 
02 cie552 image_andcamera
02 cie552 image_andcamera02 cie552 image_andcamera
02 cie552 image_andcamera
 
01 cie552 introduction
01 cie552 introduction01 cie552 introduction
01 cie552 introduction
 
Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selection
 
Csci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iiiCsci101 lect10 algorithms_iii
Csci101 lect10 algorithms_iii
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
 
Csci101 lect08b matlab_programs
Csci101 lect08b matlab_programsCsci101 lect08b matlab_programs
Csci101 lect08b matlab_programs
 
Csci101 lect08a matlab_programs
Csci101 lect08a matlab_programsCsci101 lect08a matlab_programs
Csci101 lect08a matlab_programs
 
Csci101 lect07 algorithms_ii
Csci101 lect07 algorithms_iiCsci101 lect07 algorithms_ii
Csci101 lect07 algorithms_ii
 
Csci101 lect06 advanced_looping
Csci101 lect06 advanced_loopingCsci101 lect06 advanced_looping
Csci101 lect06 advanced_looping
 

Recently uploaded

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Csci101 lect01 first_program

  • 1. CSCI 101 First Program Memory variables, input, disp, arithmetic expressions, math functions
  • 2. Overview ● Review: How to write a program? ● Substitution in mathematics & programming ● Building our first program ● Memory ● Getting input ● Displaying output ● Arithmetic expressions ● Sample programs
  • 3. Substitution in mathematics & programming ● Software evolved first to serve solving mathematical problems ● Therefore, it follows the main concepts of evaluating expressions ● Substitution in mathematical expressions works the same way in code
  • 4. Substitution in mathematics & programming 𝑥 = 4 𝑦 = 𝑒 𝑥 ● Solving the above mathematically by substituting manually step by step: 𝑦 = 𝑒√4 𝑦 = 𝑒2 𝑦 = 2.7182 𝑦 = 7.38
  • 5. Substitution in mathematics & programming ● In MATLAB, it is written as: x = 4; y = exp(sqrt(x)); ● By substituting step by step: 1. First 4 is assigned to x 2. Then x is substituted for, y = exp(sqrt(4)) 3. Function sqrt(4) is called which takes 4 as an input, gets evaluated and returns back 2, now y = exp(2) 4. Function exp(2) is called which takes 2 as an input, gets evaluated and returns back 7.38 which gets assigned to y Exercise: x = 4; y = cos(exp(x/2-2)*pi)/sin(pi/2);
  • 6. How to write a program? 1.Read the problem statement, and identify –The input and its range –The output –The relationship between the input and the output (how to compute the output) [Comprehend] 2.Write your thoughts as a sequence of steps. [Algorithm] 3.Convert these steps to Code. [Program] 4.Test your code and compare your program result against a human result. [Testing]
  • 7. Calculate area of a rectangle (Problem  Algorithm) How a computer can solve this problem? I get the values of the height and the width from you and I store them in my memory.  Get height as h Get width as w Then I multiply them in my brain and store the result in my memory  Calculate area = h*w and inform you about the resultant value.  display area
  • 8. Calculate area of a rectangle (Algorithm  Program) 1. Get height h  h=input(‘enter height: ’); 2. Get width w  w=input(‘enter width: ’); 3. Calculate area = h * w  area = h * w; 4. Display area  disp (area);
  • 9. Memory •Memory is divided into bytes •Each byte has its own address represented by binary numbers •4 or 8 bytes form a memory location to store integer or floating (Ex 10.2345) numbers •Software Programs uses letters and decimal numbers to name the memory location. 15 12 45 2 -3 4 x y sum A A1 numOfBus
  • 10. Memory Location Name (Variables) •Variable: a named space for storing a value radius •Valid names start with a letter, can contain digits. •Use meaningful variable names. •MATLAB is case sensitive (area and Area are different) Xyz 3xyz x-y ab2cd a12345 myvar AbCdE1234?
  • 11. Get input from user h=input(‘enter height: ’); Memory location to store the input Keyword to hold the program execution to get input from the keyboard Message to the user Write a Matlab statement to take the circle radius from the user and store it in ‘R’. >> enter height: 5h ? 5
  • 12. Get an array from user X=input(‘enter array elements: ’); >> enter array elements: [4 5 2 6 8] length(X): number of elements To access the array elements use X(index) Where index is an integer from 1 to length(X) What is the value of: X(4)= X(6)= 4 5 2 6 8 X(1) X(2) X(3) X(4) X(5) ?
  • 13. Display to Screen disp(h); Memory location to display Keyword to display to the screen >> 5 5 102 h disp(a); >> 102 a
  • 14. Arithmetic Expressions Operations ^ Exponentiation (5^2 is 25) *, / Multiplication and division +, - Addition and subtraction Examples x=4; y=3.5; z=2; a= x +y – 5 / (3+z); b=a + x / 2; 4 3.5 2 6.5 8.5 x y z a b Operations are executed only one at a time according to their precedence. We will study it further in future lectures
  • 15. Calculate area of a rectangle (Program and Testing) h=input(‘enter height: ’); w=input(‘enter width: ’); area = h * w; disp (area); enter height: 5 enter width: 4 20 5 4 20 h w area
  • 16. Calculate area of a circle (Algorithm, Program, Testing) 1. Get radius r 2. Calculate area = pi*r^2 3. Display area r=input(‘enter radius:’); area =pi*r^2; disp(area); enter radius: 5 49.3480 5 49.3480 radius area
  • 17. Calculate number of buses to transfer students (Algorithm) 1.Get number of students as numS 2.Get the bus capacity as busC 3.Calculate num of buses as numB = numS/busC (round up) 4. Display numB
  • 18. Calculate number of buses to transfer students (Program) numS=input(‘enter number of students:’); busC=input(‘enter bus capacity:’); numB = numS/busC; disp(numB); ceil(1.2) = 2 ceil round up to nearest integer  numB = ceil(numS/busC); If numS=60 and busC = 50 then numB = 60/50 = 1.2 ??? But it should be 2
  • 19. Calculate number of dozens and remainder (Algorithm) 1.Get a number as N 2.Calculate dozen = N/12 (no fraction) 3.Calculate the reminder (r) of dividing N by 12 4.Display dozen 5.Display r
  • 20. Calculate number of dozens and remainder (Program) N=input(‘enter a number’); dozen = N/12; r = ?? disp(dozen); disp(r); fix(5.8) = 5 fix removes the fraction rem(10,3) = 1 rem calculates the reminder of dividing 10 by 3 rem(100,2) = 0  dozen = fix(N/12);  r= rem(N,12);