Computer Programming | Teen Ink

Computer Programming

January 31, 2022
By bhosid SILVER, Fremont, California
bhosid SILVER, Fremont, California
9 articles 0 photos 0 comments

Computer Programming is a process of developing code (also called software/program) to accomplish a specific computing task. It involves understanding the task requirements and then developing code to perform that task. Code is a set of instructions which instruct processor to perform a given task. A task can be as simple as adding two numbers or it can be as complex as a complex compute operation.

Coding makes it possible for us to develop software, apps and website. Code development is done using programming languages. Commonly used programming languages are C, C++,  Java and Python.

Code is written in a specific programming language, but processor can understand only the binary format. Hence this creates a need of compiler tool. Compiler converts source code into binary code also called machine language, that is easy for processor to understand. Processor reads the binary code & performs tasks as per the instructions of Code.            

 

Few important basic elements of programming languages are:

     Data Types
     Variables
     Logical and Arithmetical Operators
     If else conditions
     Loops
     Arrays
     Functions
 

Data Types: Programming is all about the flow of data. The input data is processed by software to create an output result. Data can be of type Integer/floating/string. Integer, floating, and string datatypes are used to represent whole numbers, real numbers, and characters respectively.

Example:

var int x = 25; //x is the integer variable type, storing integer number 25

var float y = 29.9; //y is the floating variable type, storing real number 29.9

var string name1 = “David”; //name1 is the string variable type, storing characters “David”

 

Variables: Variable is a storage location which stores data. Each variable is assigned a unique name. In the example given below X is the variable storing value 100.

Example: var int X = 100;

 

Logical and Arithmetical Operators: Arithmetical operators are Add/Subtract/Multiply/ Division which are used for arithmetic operations. Logical operators Or/And/Not are used for logical operations.

Example:

var int sum, num1, num2;

sum = num1 + num2; //sum is the addition of num1 and num2

 

Conditionals: Conditionals help us make a choice based on conditional expression. If the conditional expression evaluates to true, then that portion of code is executed. If expression evaluates to false, then that portion of code is skipped.

Example:

if (a > 5)

{  <code>    }  //This code executes when expression a>5 is true

else if (b > 100)

{  <code>    } //This code executes when expression b>100 is true & expression a > 5 is false

else

{  <code>    }  //This code executes when both the expressions are false

 

Loops: Loops are great when we need something to happen repeatedly. They help in keeping the code short. Loop executes the series of code multiple times. Commonly used loop constructs are For Loop and While Loop. For Loop executes the code a fixed number of times. While Loop executes the code until condition turns false.

Example:

for (int i =0; i<100;i++)  //Executing code for 100 times

{    <code>    }

While(expression) //Executing code as long as expression is true

{    <code>    }

 

Arrays: Arrays are groups of similar types of data values that are grouped. All values in the array are of the same data type and are only differentiated by their position in the array. For example, the age of all students in a class can be an array as they will all be numbers. Similarly, the name of every person in family will be an array as all the names will be of the string data type.

Example:

int  num[5]; //num is array of 5 integers

 

Functions: Functions are used to avoid rewriting same code again and again in a program. Function contains set of instructions that can be used many times. Rather than write all the instructions every time, we can simply use the name of the function instead, and then the instructions contained within that function will execute on their own.

Example:

function Add_func (int a, int b); //Add_func is function name. This function computes sum of integers a and b.

{    int sum; sum = a + b;

      printf (“The sum of a and b =%d”,sum);

}



Similar Articles

JOIN THE DISCUSSION

This article has 0 comments.