Download as pdf or txt
Download as pdf or txt
You are on page 1of 163

Mr.

C gets Interactive
ESC101: Foundations of Computing
Purushottam Kar

ESC101: Fundamentals
of Computing
Announcements - Lab
▪ Please go to lab only on the day of your section, be on time
▪ Section-day allotment same as before (please check course website)
▪ Contact DoAA office in case section not allotted etc
▪ Please bring your IITK ID card (no PAN, Aadhar card) to lab
▪ Set your proxy to relproxy before lab starts – for minor quiz
▪ Piazza will be deactivated during lab hours Mon-Thu 2-5PM
▪ Only handwritten notes allowed in lab (no photocopies, slides etc)
▪ Do not browse internet during lab (YouTube, Google, StackExchange)
▪ Will be considered cheating
▪ In case of doubt, as TA, tutor, instructor

ESC101: Fundamentals
of Computing
Announcements - Piazza
▪ If not enrolled on Piazza or not activated account, please do so asap
▪ You will miss out on useful discussions, hints, tips
▪ May also miss out on important announcements
▪ How to use Piazza
▪ Please read etiquettes on course website
▪ Not a good thing to give out solutions (Piazza not a place to show off)
▪ When asking question
▪ Please check if it has been already answered
▪ Websites like StackExchange may ban you if you do not do this ☺
▪ Please give details of what went wrong
▪ “Why is this not working” is not at all helpful for someone trying to help you

ESC101: Fundamentals
of Computing
Fun with Integers

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c
Addition c = a + b; 5 4 9
Subtraction c = a – b; 4 5 -1
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3
Remainder c = a % b; 7 2 1
c = (a+b)/2; 5 1 3
Bracketing
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c
Addition c = a + b; 5 4 9
Subtraction c = a – b; 4 5 -1
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3
Remainder c = a % b; 7 2 1
c = (a+b)/2; 5 1 3
Bracketing
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c Recall your BODMAS
Addition c = a + b; 5 4 9
rules from high school
Subtraction c = a – b; 4 5 -1
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3
Remainder c = a % b; 7 2 1
c = (a+b)/2; 5 1 3
Bracketing
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c Recall your BODMAS
Addition c = a + b; 5 4 9
rules from high school
Subtraction c = a – b; 4 5 -1 Mr. C follows similar rules
– will see in detail soon
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3
Remainder c = a % b; 7 2 1
c = (a+b)/2; 5 1 3
Bracketing
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c Recall your BODMAS
Addition c = a + b; 5 4 9
rules from high school
Subtraction c = a – b; 4 5 -1 Mr. C follows similar rules
– will see in detail soon
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3 Good practice to
bracket your formulae
Remainder c = a % b; 7 2 1
c = (a+b)/2; 5 1 3
Bracketing
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c Recall your BODMAS
Addition c = a + b; 5 4 9
rules from high school
Subtraction c = a – b; 4 5 -1 Mr. C follows similar rules
– will see in detail soon
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3 Good practice to
bracket your formulae
Remainder c = a % b; 7 2 1
Minimize confusion as
c = (a+b)/2; 5 1 3
Bracketing well as chances of error
c = a + b/2; 5 1 5

ESC101: Fundamentals
of Computing
Fun with Integers
Operation C Code a b c Recall your BODMAS
Addition c = a + b; 5 4 9
rules from high school
Subtraction c = a – b; 4 5 -1 Mr. C follows similar rules
– will see in detail soon
Multiplication c = a * b; -2 -4 8
Division c = a / b; 7 2 3 Good practice to
bracket your formulae
Remainder c = a % b; 7 2 1
Minimize confusion as
c = (a+b)/2; 5 1 3
Bracketing well as chances of error
c = a + b/2; 5 1 5
Play with brackets in lab
to practice
ESC101: Fundamentals
of Computing
A handy shortcut

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.

ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
c = a + b; Please add them and put
the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c; a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
return 0; Please tell me value of c.
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b,c are variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add them and put
printf(“%d”,c); 9 the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; a b a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa b a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
5 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
55 4 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
55 44 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
9 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
55 44 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 9 sum.
the result in variable c.
99 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
55 44 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 99 sum.
the result in variable c.
99 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


int main(){ Hello
int a, b, c;
55 44 a,b are
a,b,c integer
are variables.
variables.
a = 5, b = 4; aa bb a = 5 and b = 4.
c = a + b; Please add tell
themmeand
their
put
printf(“%d”,c); 99 sum.
the result in variable c.
99 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


Nice! I do not have
int main(){ Hello variables
to declare
int a, b, c;
55 44 a,b
a,b,c
unless I are
areinteger
really variables.
variables.
need
a them
= 5 and☺ b = 4.
a = 5, b = 4; aa bb
c = a + b; Please add tell themmeand
their
put
printf(“%d”,c); 99 sum.
the result in variable c.
99 Goodbye
Please tell me value of c.
return 0;
} c Goodbye
ESC101: Fundamentals
of Computing
A handy shortcut
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include<stdio.h> Do you speak English?


Nice! I do not have
int main(){ Hello variables
to declare
int a, b, c;
55 44 a,b I are
a,b,c
unless integer
are
really variables.
variables.
need
a them
= 5 and ☺ b = 4.
a = 5, b = 4; aa bb
c = a + b; Please add tell them meand
their
put
printf(“%d”,c); 99 sum.
the
C result
is alsoinnot
variable c.
99 Mr
Goodbye
Please tell me
return 0; complaining that thevalue of c.
} c Goodbye
value a+b is unused
– since it got printed! ESC101: Fundamentals
of Computing
A handy tip while solving problems

ESC101: Fundamentals
of Computing
A handy tip while solving problems

ESC101: Fundamentals
of Computing
A handy tip while solving problems

ESC101: Fundamentals
of Computing
A handy tip while solving problems

I have no idea
what is going
wrong here!

ESC101: Fundamentals
of Computing
A handy tip while solving problems

I have no idea
what is going
wrong here!

ESC101: Fundamentals
of Computing
A handy tip while solving problems

I have no idea
what is going
wrong here! Try breaking up
the problem into
smaller pieces

ESC101: Fundamentals
of Computing
A handy tip while solving problems
Print your solutions to
each one of these pieces
to see where going wrong
I have no idea
what is going
wrong here! Try breaking up
the problem into
smaller pieces

ESC101: Fundamentals
of Computing
Writing pretty code is an art

ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”

ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”

int main(){
int a;
int b;
a = 5, b = 4;
a + b;
return 0;
}
ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”

int main(){
int a;
int b;
a = 5, b = 4;
a + b;
return 0;
}
ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today

int main(){
int a;
int b;
a = 5, b = 4;
a + b;
return 0;
}
ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects

int main(){
int a;
int b;
a = 5, b = 4;
a + b;
return 0;
}
ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects

int main(){ int main(){


int a; int a; // My first int
int b; int b; // The other int
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4;
return 0; a + b;
return 0;
}
} ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects
What we see
int main(){ int main(){
int a; int a; // My first int
int b; int b; // The other int
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4;
return 0; a + b;
return 0;
}
} ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects
What we see What Mr C sees
int main(){ int main(){
int a; int a; // My first int
int b; int b; // The other int
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4;
return 0; a + b;
return 0;
}
} ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects
What we see What Mr C sees
int main(){ int main(){ int main(){
int a; int a; // My first int int a;
int b; int b; // The other int int b;
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4; a = 5, b = 4;
return 0; a + b; a + b;
return 0; return 0;
}
} } ESC101: Fundamentals
of Computing
Writing pretty code is an art
Last week we learnt about “indentation”
Let us learn about “comments” today
Absolutely essential in industry, even self projects
What we see What Mr C sees
int main(){ int main(){ int main(){
int a; int a; // My first int int a;
int b; int b; // The other int int b;
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4; a = 5, b = 4;
return 0; a + b; a + b;
return 0; return 0;
}
} } ESC101: Fundamentals
of Computing
Writing pretty code is an art
Okay. I will
add your two
Last week we learnt about “indentation”
numbers
Let us learn about “comments” today
Absolutely essential in industry, even self projects
What we see What Mr C sees
int main(){ int main(){ int main(){
int a; int a; // My first int int a;
int b; int b; // The other int int b;
a = 5, b = 4; // Assign them values
a + b; a = 5, b = 4; a = 5, b = 4;
return 0; a + b; a + b;
return 0; return 0;
}
} } ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){
int a; // My first int
int b; // The other int
// Assign them values
a = 5, b = 4;
a + b;
return 0;
}

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){
int a; // My first int int a; /* My first int */
int b; // The other int int b; /* The other int */
// Assign them values /* Assign them values */
a = 5, b = 4; a = 5, b = 4;
a + b; a + b;
return 0; return 0;
} }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
a + b; a + b; a + b;
return 0; return 0; return 0;
} } }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
a + b; a + b; a + b;
return 0; return 0; return 0;
} } }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
a + b; So I can mix a + b; a + b;
return 0; and match? return 0; return 0;
} } }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
a + b; So I can mix a + b; a + b;
return 0; and match? return 0; return 0;
} } }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
Yes. In fact /* */ is used
a + b; So I can mix a + b; a + b;
to comment several
return 0; and match? return 0; return 0;
lines at once – shortcut!
} } }

ESC101: Fundamentals
of Computing
Commenting Styles
Since it is an art form, artists differ on what is more pretty
int main(){ int main(){ int main(){
int a; // My first int int a; /* My first int */ int a; // My first int
int b; // The other int int b; /* The other int */ int b; // The other int
// Assign them values /* Assign them values */ /* Assign them values */
a = 5, b = 4; a = 5, b = 4; a = 5, b = 4;
Yes. In fact /* */ is used
a + b; So I can mix a + b; a + b;
to comment several
return 0; and match? return 0; return 0;
lines at once – shortcut!
} } }
Just be a bit careful.
Some compilers don’t
understand // comments ESC101: Fundamentals
of Computing
More on Comments

ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you
defined each variable and what
each step of your code is doing

ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you
defined each variable and what
each step of your code is doing
You will thank yourself for doing this when you
are looking at your own code before the
endsem exams ☺ ☺

ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you
defined each variable and what
each step of your code is doing
You will thank yourself for doing this when you
are looking at your own code before the
endsem exams ☺ ☺
Your team members in your
company/research group will also thank you

ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you
defined each variable and what
each step of your code is doing
You will thank yourself for doing this when you
are looking at your own code before the
endsem exams ☺ ☺
Your team members in your
company/research group will also thank you
Multiline comments very handy. No
need to write // on every line ☺

ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you int main(){
defined each variable and what int a; // My first int
each step of your code is doing
You will thank yourself for doing this when you
int b; // The other int
are looking at your own code before the /* Assign them values
endsem exams ☺ ☺
Your team members in your
so that I can add
company/research group will also thank you them later on */
Multiline comments very handy. No a = 5, b = 4;
need to write // on every line ☺ a + b;
return 0;
}
ESC101: Fundamentals
of Computing
More on Comments
Use comments to describe why you int main(){
defined each variable and what int a; // My first int
each step of your code is doing
You will thank yourself for doing this when you
int b; // The other int
are looking at your own code before the /* Assign them values
endsem exams ☺ ☺
Your team members in your
so that I can add
company/research group will also thank you them later on */
Multiline comments very handy. No a = 5, b = 4;
need to write // on every line ☺ a + b;
return 0;
}
ESC101: Fundamentals
of Computing
A handy tip while solving problems

ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error

ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Mr C will tell you (compile) where he thinks the error is

ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){
int a, b;
c = a + b;
a = 5;
b = 4;
return 0;
}
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){
int a, b;
c = a + b;
a = 5;
b = 4;
return 0;
}
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){
int a, b;
c = a + b;
a = 5;
b = 4;
return 0;
}
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b;
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b;
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b;
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b;
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b; Aha! I forgot
to declare c
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){


int a, b; int a, b;
c = a + b; // c = a + b;
a = 5; a = 5;
b = 4; b = 4;
return 0; return 0;
} }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){ int main(){


int a, b; int a, b; int a, b, c;
c = a + b; // c = a + b; c = a + b;
a = 5; a = 5; a = 5;
b = 4; b = 4; b = 4;
return 0; return 0; return 0;
} } }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){ int main(){


int a, b; int a, b; int a, b, c;
c = a + b; // c = a + b; c = a + b;
a = 5; a = 5; a = 5;
b = 4; b = 4; b = 4;
return 0; return 0; return 0;
} } }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){ int main(){


int a, b; int a, b; int a, b, c;
c = a + b; // c = a + b; c = a + b;
a = 5; a = 5; a = 5;
b = 4; b = 4; b = 4;
return 0; return 0; return 0;
} } }
ESC101: Fundamentals
of Computing
A handy tip while solving problems
Comments can be also used to identify where is error
Error! Okay! Okay!
Mr C will tell you (compile) where he thinks the error is
Commenting out lines can also help identify the error

int main(){ int main(){ int main(){


int a, b; int a, b; int a, b, c;
c = a + b; // c = a + b; c = a + b;
a = 5; a = 5; a = 5;
b = 4; b = 4; b = 4;
return 0; return 0; return 0;
} } }
ESC101: Fundamentals
of Computing
Most Awaited scanf ☺

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code
▪ Also called “hardcoding”

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code
▪ Also called “hardcoding”
▪ A bit like a calculator which can only add 5 and 4 ☺

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code
▪ Also called “hardcoding”
▪ A bit like a calculator which can only add 5 and 4 ☺
▪ To add 6 and 9, write a new calculator 

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code
▪ Also called “hardcoding”
▪ A bit like a calculator which can only add 5 and 4 ☺
▪ To add 6 and 9, write a new calculator 
▪ Can’t we ask Mr C to request us for the numbers
when he is executing our requests i.e. at runtime?

ESC101: Fundamentals
of Computing
Most Awaited scanf ☺
▪ A bit frustrating
▪ Mr C can add two numbers but both have to be written into code
▪ Also called “hardcoding”
▪ A bit like a calculator which can only add 5 and 4 ☺
▪ To add 6 and 9, write a new calculator 
▪ Can’t we ask Mr C to request us for the numbers
when he is executing our requests i.e. at runtime?
▪ Of course – take input from the user using scanf

ESC101: Fundamentals
of Computing
Adding two unknown numbers

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
scanf(“%d”, &b); Please ask me for value of b.
Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye

ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
scanf(“%d”, &a); Please ask me for value of a.
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
Please give Please print their sum.
printf(“%d”,
me input a + b);
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
Please give Please print their sum.
printf(“%d”,
me input a + b);
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
Please give Please print their sum.
printf(“%d”,
me input a + b);
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
Thanks. Let me a b
scanf(“%d”, Please ask me for value of a.
get back to&a);
work
scanf(“%d”, &b); Please ask me for value of b.
Please give Please print their sum.
printf(“%d”,
me input a + b);
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ 3 Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ 3 8 Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ 3 8 Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); 11 Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Adding two unknown numbers
HOW WE MUST SPEAK TO MR. COMPILER HOW WE USUALLY SPEAK TO A HUMAN

#include <stdio.h> Do you speak English?


int main(){ 3 8 Hello
int a, b; a, b are two variables.
a b Please ask me for value of a.
scanf(“%d”, &a);
scanf(“%d”, &b); 11 Please ask me for value of b.
printf(“%d”, a + b); Please print their sum.
11 Goodbye
return 0;
} ESC101: Fundamentals
of Computing
Words of Caution

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a);

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a);

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks
Tomorrow, will learn shorthand for multiple inputs

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks
Tomorrow, will learn shorthand for multiple inputs

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks
Tomorrow, will learn shorthand for multiple inputs

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks
Tomorrow, will learn shorthand for multiple inputs

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks
Tomorrow, will learn shorthand for multiple inputs

ESC101: Fundamentals
of Computing
Words of Caution
In Prutor, input has to be specified before “Execute”
Please be very careful about this common mistake

scanf(“%d”,a); scanf(“%d”,&a);
Will explain what this & means, in few weeks Both work!
Tomorrow, will learn shorthand for multiple inputs
Experiment!

ESC101: Fundamentals
of Computing

You might also like