SlideShare a Scribd company logo
1
Some influential ones:
FORTRAN
science / engineering
COBOL
business data
LISP
logic and AI
BASIC
a simple language
2
Languages
Programming basics
code or source code: The
sequence of instructions
in a program.
syntax: The set of legal
structures and commands
that can be used in a
particular programming
language.
output: The messages
printed to the user by a
program.
console: The text box
onto which output is
printed.
3
Compiling and interpreting
Many languages require you to
compile (translate) your
program into a form that the
machine understands.
Python is instead directly
interpreted into machine
instructions.
4
compile execute
output
source code
Hello.java
byte code
Hello.class
interpret
output
source code
Hello.py
Dimensions of aPL
• Functional
• Treatscomputation as the evaluation ofmathematical functions
(e.g. Lisp, Scheme, Haskell, etc.)
• Imperative
• describes computation in terms of statements that changea program
state (e.g. FORTRAN, BASIC, Pascal, C, etc. )
• Logical (declarative)
• expresses the logic of a computation withoutdescribingits control flow
(e.g. Prolog)
• Object oriented
• uses "objects"– data structures consistingof data fields and methods
together with their interactions– to design applications and computer
programs (e.g. C++, Java, C#, Python, etc.)
Slide credit: Thomas J. Cortina
C (1973)
• Developed by Ken Thompson and Dennis Ritchie at
AT&T Bell Labs for use on the UNIXoperating system.
– now used on practicallyevery operatingsystem
– popular languagefor writing system software
• Features:
– An extremely simple core language, with non-essential
functionality provided by a standardizedsetof library routines.
– Low-level access to computer memory via the use of pointers.
• C ancestors: C++, C#, Java
9
Slide credit: Thomas J. Cortina
Python
• Created by Guido van Rossum in the late 1980s
• Allows programming in multiple paradigms: object-
oriented, structured,functional
• Uses dynamic typing and garbage collection
8
Building a simple program in
Python (as compared to C)
• Compilers versusinterpreters
• Variable declarations
• Whitespace
• The printf() function
• Functions
9
Compilers versus interpreters
• One major difference between C and Python is how the
programs written in these two languages are executed.
• With C programs, you usually use a compiler when you
are ready to see a C program execute.
• By contrast, with Python, you typically use an interpreter.
10
Compilers versus interpreters
• An interpreter reads the user-written programand
performs it directly.
• A compiler generates a file containing the translation
of the program into the machine's native code.
– The compiler does not actually execute the program!
– Instead, you first execute the compiler to create a native
executable, and then you execute the generatedexecutable.
11
Variable declarations
• C requires variable declarations, informing the compiler
about the variable before the variable is actuallyused.
• In C, the variable declaration defines the variable'stype.
• No such thing in Python!
20
Declaring a Variable
• Declaring a variable is simpleenough.
• You enter the variable's type, somewhitespace,
the variable's name, and a semicolon:
double x;
• Value assignment is similar toPython:
x=3;
• x will actually hold the floating-pointvalue 3.0 rather than the
integer3.
• However, once you declare a variable to be of a particular
type, you cannot change itstype!
13
Declaring a Variable
• In C, variable declarations belong at the top of the
function in which they areused.
• If you forget to declare a variable, the compiler will
refuse to compile theprogram:
– A variable is used but is notdeclared.
• To a Python programmer, it seems a pain to have to
include these variable declarations in a program, though
this gets easier with morepractice.
14
Whitespace
• In Python, whitespace characters like tabs andnewlines
are important:
– You separate your statements by placingthem on separate
lines, and you indicate the extent of a block using
indentation.
– like the body of a while or if statement
• C does not use whitespace except for separatingwords.
• Most statements are terminated with a semicolon ';', and
blocks of statementsare indicated using a set of braces, '{'
and '}'.
Whitespace
15
C fragment
disc = b * b - 4 * a * c;
if (disc < 0)
{
num_sol = 0;
}
else
{
t0 = -b / a;
if (disc == 0)
{
num_sol = 1;
sol0 = t0 / 2;
}
else
{
num_sol = 2;
t1 = sqrt(disc) / a;
sol0 = (t0 + t1) / 2;
sol1 = (t0 - t1) / 2;
}
}
Python equivalent
disc = b * b - 4 * a * c
if disc < 0:
num_sol = 0
else:
t0 = -b
if disc
/ a
== 0:
num_sol = 1
sol0 = t0 / 2
else:
num_sol = 2
**
t1 = disc
sol0
sol1
= (t0 +
= (t0 -
0.5 / a
t1) / 2
t1) / 2
16
Whitespace
• As said, whitespace is insignificant in C.
• The computer would be just as happy if the previous code
fragment is written as follows:
disc=b*b-4*a*c;if(disc<0){
num_sol=0;}else{t0=-b/a;if(
disc==0){num_sol=1;sol0=t0/2
;}else{num_sol=2;t1=sqrt(disc/a;
sol0=(t0+t1)/2;sol1=(t0-t1)/2;}}
• However, do not write your programs like this!
30
Functions
• Unlike Python, all C code must be nested within functions,
and functions cannot be nested withineach other.
• A C program's overall structure is typicallyvery
straightforward.
• It is a list of function definitions, one after another, each
containing a list of statements to be executed when the
function iscalled.
18
Functions
• A C function is defined bynamingthe return type, followed bythe function
name, followed bya set of parentheses listing the parameters.
• Each parameter is described by includingthe type of the parameter and the
parametername.
• Here's a simple example of a function definition:
float expon(float b, int e)
{
if (e == 0)
{
return 1.0;
}
else
{
return b * expon(b, e - 1);
}
}
This is a function named
expon, which takes two
arguments, first a floating point
number and next an integer,
and returns a floating point
number.
19
Functions
• If you have a function that does not have any useful
return value, then you'd use void as the return type.
• Programs have one special function named main, whose
return type is aninteger.
• This function is the “starting point” for the program:
– The computer essentially calls the program's mainfunction
when it wants to execute theprogram.
– The integer return value is largely meaningless; we'll
always return 0 rather than worrying about howthe return
value might beused.
Functions
20
C program
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
else
{
return gcd(b, a % b);
}
}
int main()
{
printf("GCD: %dn“, gcd(24,40));
return 0;
}
Python program
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
print("GCD: " + str(gcd(24, 40)))

More Related Content

PPTX
Unit-1_c.pptx you from the heart of the day revision
PPTX
Programming in C & Decision Making Branching
PPTX
Programming in C and Decision Making Branching
PDF
PPTX
Btech i pic u-1 introduction to c language
PPTX
introduction to c language
PPTX
Mca i pic u-1 introduction to c language
PPTX
Diploma ii cfpc u-1 introduction to c language
Unit-1_c.pptx you from the heart of the day revision
Programming in C & Decision Making Branching
Programming in C and Decision Making Branching
Btech i pic u-1 introduction to c language
introduction to c language
Mca i pic u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c language

Similar to Lecture 1.pptx (20)

PPTX
Bsc cs i pic u-1 introduction to c language
PPTX
Programming in c
PPTX
Programming in C
PPTX
chapter 1.pptx
PPT
C Lang notes.ppt
PPTX
Introduction to C Programming Language.pptx
PPTX
C programming
PDF
Programming Fundamentals and basic knowledge
PDF
C-PROGRAMMING pdf text book notes vtu important
PPTX
C programming
PDF
Programming in c
PPTX
Best Computer Institute in Pitampura, Delhi, Learn from Industry Experts.
PPTX
Introduction to C Programming
PPTX
Computer Programming In C.pptx
PDF
Introduction to C programming
PPTX
Intoduction to c language
PPTX
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
PPTX
Introduction to c language
PDF
C programme presentation
Bsc cs i pic u-1 introduction to c language
Programming in c
Programming in C
chapter 1.pptx
C Lang notes.ppt
Introduction to C Programming Language.pptx
C programming
Programming Fundamentals and basic knowledge
C-PROGRAMMING pdf text book notes vtu important
C programming
Programming in c
Best Computer Institute in Pitampura, Delhi, Learn from Industry Experts.
Introduction to C Programming
Computer Programming In C.pptx
Introduction to C programming
Intoduction to c language
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
Introduction to c language
C programme presentation
Ad

Recently uploaded (20)

PPTX
Software Engineering and software moduleing
PDF
Visual Aids for Exploratory Data Analysis.pdf
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
communication and presentation skills 01
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Module 8- Technological and Communication Skills.pptx
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPTX
CyberSecurity Mobile and Wireless Devices
PPTX
Information Storage and Retrieval Techniques Unit III
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
PDF
distributed database system" (DDBS) is often used to refer to both the distri...
Software Engineering and software moduleing
Visual Aids for Exploratory Data Analysis.pdf
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
communication and presentation skills 01
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Module 8- Technological and Communication Skills.pptx
August -2025_Top10 Read_Articles_ijait.pdf
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
CyberSecurity Mobile and Wireless Devices
Information Storage and Retrieval Techniques Unit III
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Current and future trends in Computer Vision.pptx
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
ChapteR012372321DFGDSFGDFGDFSGDFGDFGDFGSDFGDFGFD
distributed database system" (DDBS) is often used to refer to both the distri...
Ad

Lecture 1.pptx

  • 1. 1
  • 2. Some influential ones: FORTRAN science / engineering COBOL business data LISP logic and AI BASIC a simple language 2 Languages
  • 3. Programming basics code or source code: The sequence of instructions in a program. syntax: The set of legal structures and commands that can be used in a particular programming language. output: The messages printed to the user by a program. console: The text box onto which output is printed. 3
  • 4. Compiling and interpreting Many languages require you to compile (translate) your program into a form that the machine understands. Python is instead directly interpreted into machine instructions. 4 compile execute output source code Hello.java byte code Hello.class interpret output source code Hello.py
  • 5. Dimensions of aPL • Functional • Treatscomputation as the evaluation ofmathematical functions (e.g. Lisp, Scheme, Haskell, etc.) • Imperative • describes computation in terms of statements that changea program state (e.g. FORTRAN, BASIC, Pascal, C, etc. ) • Logical (declarative) • expresses the logic of a computation withoutdescribingits control flow (e.g. Prolog) • Object oriented • uses "objects"– data structures consistingof data fields and methods together with their interactions– to design applications and computer programs (e.g. C++, Java, C#, Python, etc.)
  • 6. Slide credit: Thomas J. Cortina C (1973) • Developed by Ken Thompson and Dennis Ritchie at AT&T Bell Labs for use on the UNIXoperating system. – now used on practicallyevery operatingsystem – popular languagefor writing system software • Features: – An extremely simple core language, with non-essential functionality provided by a standardizedsetof library routines. – Low-level access to computer memory via the use of pointers. • C ancestors: C++, C#, Java 9
  • 7. Slide credit: Thomas J. Cortina Python • Created by Guido van Rossum in the late 1980s • Allows programming in multiple paradigms: object- oriented, structured,functional • Uses dynamic typing and garbage collection
  • 8. 8 Building a simple program in Python (as compared to C) • Compilers versusinterpreters • Variable declarations • Whitespace • The printf() function • Functions
  • 9. 9 Compilers versus interpreters • One major difference between C and Python is how the programs written in these two languages are executed. • With C programs, you usually use a compiler when you are ready to see a C program execute. • By contrast, with Python, you typically use an interpreter.
  • 10. 10 Compilers versus interpreters • An interpreter reads the user-written programand performs it directly. • A compiler generates a file containing the translation of the program into the machine's native code. – The compiler does not actually execute the program! – Instead, you first execute the compiler to create a native executable, and then you execute the generatedexecutable.
  • 11. 11 Variable declarations • C requires variable declarations, informing the compiler about the variable before the variable is actuallyused. • In C, the variable declaration defines the variable'stype. • No such thing in Python!
  • 12. 20 Declaring a Variable • Declaring a variable is simpleenough. • You enter the variable's type, somewhitespace, the variable's name, and a semicolon: double x; • Value assignment is similar toPython: x=3; • x will actually hold the floating-pointvalue 3.0 rather than the integer3. • However, once you declare a variable to be of a particular type, you cannot change itstype!
  • 13. 13 Declaring a Variable • In C, variable declarations belong at the top of the function in which they areused. • If you forget to declare a variable, the compiler will refuse to compile theprogram: – A variable is used but is notdeclared. • To a Python programmer, it seems a pain to have to include these variable declarations in a program, though this gets easier with morepractice.
  • 14. 14 Whitespace • In Python, whitespace characters like tabs andnewlines are important: – You separate your statements by placingthem on separate lines, and you indicate the extent of a block using indentation. – like the body of a while or if statement • C does not use whitespace except for separatingwords. • Most statements are terminated with a semicolon ';', and blocks of statementsare indicated using a set of braces, '{' and '}'.
  • 15. Whitespace 15 C fragment disc = b * b - 4 * a * c; if (disc < 0) { num_sol = 0; } else { t0 = -b / a; if (disc == 0) { num_sol = 1; sol0 = t0 / 2; } else { num_sol = 2; t1 = sqrt(disc) / a; sol0 = (t0 + t1) / 2; sol1 = (t0 - t1) / 2; } } Python equivalent disc = b * b - 4 * a * c if disc < 0: num_sol = 0 else: t0 = -b if disc / a == 0: num_sol = 1 sol0 = t0 / 2 else: num_sol = 2 ** t1 = disc sol0 sol1 = (t0 + = (t0 - 0.5 / a t1) / 2 t1) / 2
  • 16. 16 Whitespace • As said, whitespace is insignificant in C. • The computer would be just as happy if the previous code fragment is written as follows: disc=b*b-4*a*c;if(disc<0){ num_sol=0;}else{t0=-b/a;if( disc==0){num_sol=1;sol0=t0/2 ;}else{num_sol=2;t1=sqrt(disc/a; sol0=(t0+t1)/2;sol1=(t0-t1)/2;}} • However, do not write your programs like this!
  • 17. 30 Functions • Unlike Python, all C code must be nested within functions, and functions cannot be nested withineach other. • A C program's overall structure is typicallyvery straightforward. • It is a list of function definitions, one after another, each containing a list of statements to be executed when the function iscalled.
  • 18. 18 Functions • A C function is defined bynamingthe return type, followed bythe function name, followed bya set of parentheses listing the parameters. • Each parameter is described by includingthe type of the parameter and the parametername. • Here's a simple example of a function definition: float expon(float b, int e) { if (e == 0) { return 1.0; } else { return b * expon(b, e - 1); } } This is a function named expon, which takes two arguments, first a floating point number and next an integer, and returns a floating point number.
  • 19. 19 Functions • If you have a function that does not have any useful return value, then you'd use void as the return type. • Programs have one special function named main, whose return type is aninteger. • This function is the “starting point” for the program: – The computer essentially calls the program's mainfunction when it wants to execute theprogram. – The integer return value is largely meaningless; we'll always return 0 rather than worrying about howthe return value might beused.
  • 20. Functions 20 C program int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } int main() { printf("GCD: %dn“, gcd(24,40)); return 0; } Python program def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) print("GCD: " + str(gcd(24, 40)))