Showing posts with label Computer Programming. Show all posts
Showing posts with label Computer Programming. Show all posts

Monday, May 1, 2017

Computer Programming - Summary

Computer programming is defined as telling a computer what to do through a special set of instructions which are then interpreted by the computer to perform some task(s). These instructions can be specified in one or more programming languages including Java, Python, C, and C++.

A computer goes through a set of steps whose purpose is to achieve something. These steps are instructed to the computer by computer programs. Essentialy, computer programming is the process by which these programs are designed and implemented.

Computer Programming - File I/O

Computer Files
A computer file is used to store data in digital format like plain text, image data, or any other content. Computer files can be organized inside different directories. Files are used to keep digital data, whereas directories are used to keep files.

Computer files can be considered as the digital counterpart of paper documents. While programming, you keep your source code in text files with different extensions, for example, C programming files end with the extension .c, Java programming files with .java, and Python files with .py.

Computer Programming - Functions

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. You have already seen various functions like printf() and main(). These are called built-in functions provided by the language itself, but we can write our own functions as well and this tutorial will teach you how to write and use those functions in C programming language.

Good thing about functions is that they are famous with several names. Different programming languages name them differently, for example, functions, methods, sub-routines, procedures, etc.

Computer Programming - Strings

During our discussion about characters, we learnt that character data type deals with a single character and you can assign any character from your keyboard to a character type variable.

Now, let's move a little bit ahead and consider a situation where we need to store more than one character in a variable. We have seen that C programming does not allow to store more than one character in a character type variable. So the following statements are invalid in C programming and produce syntax errors −

Computer Programming - Arrays

Consider a situation where we need to store five integer numbers. If we use programming's simple variable and data type concepts, then we need five variables of int data type and the program will be as follows −

#include <stdio.h>

main() {

   int  number1;
   int  number2;
   int  number3;
   int  number4;
   int  number5;
   

Computer Programming - Characters

If it was easy to work with numbers in computer programming, it would be even easier to work with characters. Characters are simple alphabets like a, b, c, d...., A, B, C, D,....., but with an exception. In computer programming, any single digit number like 0, 1, 2,....and special characters like $, %, +, -.... etc., are also treated as characters and to assign them in a character type variable, you simply need to put them inside single quotes. For example, the following statement defines a character type variable ch and we assign a value 'a' to it −

char ch = 'a';

Saturday, April 29, 2017

Computer Programming - Numbers

Every programming language provides support for manipulating different types of numbers such as simple whole integers and floating point numbers. C, Java, and Python categorize these numbers in several categories based on their nature.

Let's go back and check the data types chapter, where we listed down the core data types related to numbers −
Type Keyword Value range which can be represented by this data type
Number int -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
Small Number short -32,768 to 32,767
Long Number long -2,147,483,648 to 2,147,483,647
Decimal Number float 1.2E-38 to 3.4E+38 till 6 decimal places

Computer Programming - Loops

Let's consider a situation when you want to print Hello, World! five times. Here is a simple C program to do the same −

#include <stdio.h>

main() {

   printf( "Hello, World!\n");
   printf( "Hello, World!\n");
   printf( "Hello, World!\n");
   printf( "Hello, World!\n");
   printf( "Hello, World!\n");

}

Wednesday, April 26, 2017

Computer Programming - Decisions

Decision making is critical to computer programming. There will be many situations when you will be given two or more options and you will have to select an option based on the given conditions. For example, we want to print a remark about a student based on his secured marks. Following is the situation −

Assume given marks are x for a student:

If given marks are more than 95, then
Student is brilliant

Computer Programming - Operators

An operator in a programming language is a symbol that tells the compiler or interpreter to perform specific mathematical, relational or logical operation and produce final result. This chapter will explain the concept of operators and it will take you through the important arithmetic and relational operators available in C, Java, and Python.

Arithmetic Operators
Computer programs are widely used for mathematical calculations. We can write a computer program which can do simple calculation like adding two numbers (2 + 3) and we can also write a program, which can solve a complex equation like P(x) = x4 + 7x3 - 5x + 9.

Tuesday, April 25, 2017

Computer Programming - Keywords

So far, we have covered two important concepts called variables and their data types. We discussed how to use int, long, and float to specify different data types. We also learnt how to name the variables to store different values.

Though this chapter is not required separately because reserved keywords are a part of basic programming syntax, we kept it separate to explain it right after data types and variables to make it easy to understand.

Computer Programming - Variables

Variables are the names you give to computer memory locations which are used to store values in a computer program.

For example, assume you want to store two values 10 and 20 in your program and at a later stage, you want to use these two values. Let's see how you will do it. Here are the following three simple steps −

Computer Programming - Data Types

Let's discuss about a very simple but very important concept available in almost all the programming languages which is called data types. As its name indicates, a data type represents a type of the data which you can process using your computer program. It can be numeric, alphanumeric, decimal, etc.

Let’s keep Computer Programming aside for a while and take an easy example of adding two whole numbers 10 & 20, which can be done simply as follows −

Monday, April 24, 2017

Computer Programming - Basic Syntax

Let’s start with a little coding, which will really make you a computer programmer. We are going to write a single-line computer program to write Hello, World! on your screen. Let’s see how it can be written using different programming languages.

Hello World Program in C
Try the following example using our online compiler option available at www.compileonline.com.

Sunday, April 23, 2017

Computer Programming - Environment

Though Environment Setup is not an element of any Programming Language, it is the first step to be followed before setting on to write a program.

When we say Environment Setup, it simply implies a base on top of which we can do our programming. Thus, we need to have the required software setup, i.e., installation on our PC which will be used to write computer programs, compile, and execute them. For example, if you need to browse Internet, then you need the following setup on your machine −

Computer Programming - Basics

We assume you are well aware of English Language, which is a well-known Human Interface Language. English has a predefined grammar, which needs to be followed to write English statements in a correct way. Likewise, most of the Human Interface Languages (Hindi, English, Spanish, French, etc.) are made of several elements like verbs, nouns, adjectives, adverbs, propositions, and conjunctions, etc.

Computer Programming - Overview

Introduction to Computer Program
Before getting into computer programming, let us first understand computer programs and what they do.
A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.

The two important terms that we have used in the above definition are −