## Working on logic for computer programs

• Every computer programming language, gives us the following

• Some way to allocate memory in RAM
• Some way to execute instructions
• Whole library to perform common actions
• DataType: Easier interface to allocate memory to our program.

``````int a
char b
float c
``````
• Datatypes request memory of certain type & size to the OS which in turn allocates the memory to the process.

• Two kinds of languages based on datatyping

• Statically typed programming languages: In these programming languages we need to specify data type. Eg C, C++, Java, C#
``````int a = 10
string b = 'hello'
``````
• Dynamically typed programming languages: In these programming languages it is not necessary to specify types, Types are assigned dynamically depending on values passed to it. Eg python, ruby ….
``````a = 10
b = 'hello'
``````
• To execute the code, we need operators and Every programming language provides operators

• Arthimetic
• Comparision
• Logical
• String/Text
• Lets define the operators which Jarvis knows

• /
• % • = Assigment • Using what Jarvis knows so far lets try to find

• if the number is even or odd
``````Hi Jarvis,
number = 10
number % 2 and if it is zero then it is even number else odd number
``````
• Simple Leap year: If the year is divisible by 4 it is a leap year.
``````Hi Jarvis
year = 2004
calculate year % 4 and check if the value is zero then leap year
``````
• Exercise:

• Write to Jarvis to calculate
• square of the number
• Area of the rectangle (length * breadth)
• find the reverse of the number (35 => 53 )

This site uses Akismet to reduce spam. Learn how your comment data is processed. 