Lets get to know more about programming
-
Programming is all about writing a sequence of instructions
-
Lets try to calculate area of circle and the steps in that:
-
To allocate memory in the RAM, we also need to specify the size/amount of memory and the address of the memory (generally represented as hexa decimal numbers)
-
All programming languages support some thing called as data types which will inform OS how much memory is to be allocated.
-
Some of the popular data types are
- int
- float
- bool
-
To solve the problem of referring memory addresses, all programming languages support the concept of references or alias
int a # allocate a memory location to store integers and i will be referring the value in memory by using a
float b # allocate a memory location to store decimal and i will be referring the value in memory by using b
- Now on the memory if we need perform operations (i.e. assign a value)
int a = 10
a = 11
- Some languages like python will not even expect to use data types for allocating memory (Dynamic languages)
a = 10
a = 11
b = 10.5
c = True
-
So now we know little bit about allocating memory for our programs
-
Now we need to use the values in the memory to perform some operations, Every language to perform operations on memory has operators
- + : add
- –: subtract
- *: multiply
- /: division
- //: integer division
- %: reminder or modulus
- =: assignment
- ==: equals to
- !=: not equals to
-
Lets use the knowledge we have gained to calculate area of rectangle by speaking with Jarvis
Hi Jarvis
length = 100 # Allocate memory for 100 and call it as length
breadth = 100 # Allocate memory for 100 and call it as breadth
print length * breadth
- Lets use the knowledge we have gained to calculate simple interest by speaking with Jarvis
Hi Jarvis
principal = 10000
rate = 10
time = 5
print principal * time * rate / 100