You are on page 1of 8

Programming Fundamentals

DEFINITION OF PROGRAMMING:
A vocabulary and set of grammatical rules for instructing a computer
to perform specific tasks.
These instruction can be high level languages or low level languages.
But now these terms programming languages usually refers to highlevel languages, such as BASIC, C, C++, COBOL, FORTRAN, and Pascal. Each
language has a unique set of keywords (words that it understands) and a
special syntax for organizing program instructions.
High-level programming languages, while similar compared to human
languages, and simpler than the languages the computer actually
understands, called machine languages.

HISTORY OF PROGRAMMING LANGUAGES:


In Programming, here we have four Generations
1st Generation: (Machine Dependent)
Machine languages (first-generation languages) are the most basic type of
computer languages, consisting of strings of numbers the computer's
hardware can use.
2nd Generation: (Low Level Languages)
Assembly languages are only somewhat easier to work with than
machine languages.
Developers use cryptic English-like phrases to represent strings of
numbers.
Assembler is used to translate the code into object code.
3rd Generation: (Middle Level Languages)
These languages are machine independent.
Examples of 3rd Generation are:
FORTRON, COBOL, PASCAL, C, BASIC, etc.
4th Generation: (High Level Languages)
This generation may use a text-based environment (like a 3rd Generation) or
may allow the programmer to work in a visual environment, using graphical
tools.
1

Programming Fundamentals

Examples of 4th Generation are:


VB, VISUAL AGE, JAVA, C++, C# etc

COMPILER:
Compiler translate the whole program into machine language.
It makes a file called Object File (Machine oriented File)
It shows the error list at the end of compilation.

INTERPRETER:
Interpreter reads the instruction line by line.
It convert the code into machine after execute.
If any error occurs then interpreter stop and show the errors.

VARIABLES & DATA TYPES:


Variables are memory location in computer's memory to store data. To
indicate the memory location, each variable should be given a unique name
called identifier. Variable names are just the symbolic representation of a
memory location. Examples of variable name: a, b, c, sum, count, etc.
Example:
Int a;
Int sum;
C language has three basic data types:

1) Integers Values:
Integer values are the numeric constants numbers without any fractional
part or exponential part.
There are two types of integers in C language:
TYPE
SHORT INT
LONG INT

MEMORY
2 BYTES
4 BYTES

RANGE
-32768 to +32767
-231 to +231 -1

Programming Fundamentals

Floating Values:
Floating point values are the numeric constants that has either fractional
form or exponent form.
TYPE
FLOAT
DOUBLE
LONG DOUBLE

MEMORY

RANGE
10 to 1038
10-308 to 10308
Same as Double, but
have some special
features
-.38

4 BYTES
8 BYTES
10 BYTES

Character:
Character are the constant which use single quotation around characters.
For example: 'a', 'U', 'Z', 'b' etc.

ESCAPE SEQUENCE:
\n
\t
\b
\r
\f
\
\
\\

New Line
Tab
Backspace
Carriage Return
Formatted
Single Quote
Double Quotes
Backslash

LOOPS:
In computer programming, a loop is a sequence of instruction s that is
continually repeated until a certain condition is reached. Typically, a certain
process is done, such as getting an item of data and changing it, and then
some condition is checked such as whether a counter has reached a
prescribed number.

1) FOR LOOP:
Expression:
for (initialization statement; test expression; update statement) {
Code/s to be executed;
}

Programming Fundamentals

Flow Chart:

Example 01:
Print Hello World Ten Times:
#include<stdio.h>
int main()
{
int i;
for (i = 0; i < 10; i++)
{
printf ("Hello\n");
printf ("World\n");
}
return 0;
}
Example 02:
Write a program to find the sum of first n natural numbers where n is
entered by user. Note: 1,2,3... are called natural numbers.

#include <stdio.h>
int main(){
4

Programming Fundamentals

int n, count, sum=0;


printf("Enter the value of n.\n");
scanf("%d",&n);
for (count=1;count<=n;++count) //for loop terminates if count>n
{
sum+=count; /* this statement is equivalent to
sum=sum+count */
}
printf("Sum=%d",sum);
return 0;
}

2) WHILE LOOP:
Expression:
while (test expression) {
Statement/s to be executed.
}
Flow Chart:

Programming Fundamentals

Example 03:
#include<stdio.h>
int main()
{
int counter, howmuch;
scanf("%d", &howmuch);
counter = 0;
while ( counter < howmuch)
{
counter++;
printf("%d\n", counter);
}
return 0;
}

Example 04:
#include<stdio.h>
int main(void) {
int i;
i = 0;
while(i++ < 5) {
printf("%d\n", i);
}
printf("\n");
i = 0;
while(++i < 5) {
printf("%d\n", i);
}
return 0;
}

3) DO WHILE LOOP:
Expression:
6

Programming Fundamentals

do {
Some code/s;
}
while (test expression);
Flow Chart:

Example 05:

Write a C program to add all the numbers entered by a user until user
enters 0.

/*C program to demonstrate the working of do...while statement*/


#include <stdio.h>
int main(){
int sum=0,num;
do
/* Codes inside the body of do...while loops are at least
executed once. */
7

Programming Fundamentals

{
printf("Enter a number\n");
scanf("%d",&num);
sum+=num;
}
while(num!=0);
printf("sum=%d",sum);
return 0;
}

You might also like