Sie sind auf Seite 1von 68

Computer Fundamentals and

Programming

Montaigne Garcia Molejon

Computer Programming
Computer programming (often shortened to
programming) is a set of step-by-step
instructions that directs the computer to do
the tasks you want it to do and produce the
results you want.

Mechanical Age
(1450 1840 A.D.)
In this period, the information explosion and
the first general purpose computers was
exist and some computing devices which are
manually operated began to emerged and
more developers began to explore with their
own invention.

Charles Babbage
(1791 - 1871)
the invention of Charles

Charles Babbage

Babbage which earn him the


title as the Father of the
Modern Computer. Charles
Babbage is an English
mathematician of the
nineteenth century who
proposed a steam driven
calculating machine around
1800. He invented the
Difference Engine(1821) and
Analytical Engine(1832).

Babbages Difference
Engine
- this machine would be
able to compute tables of
numbers, such as logarithm
tables and was designed to
automate a standard procedure
for calculating roots of
polynomials. This first
difference engine would have
been composed of around
25,000 parts, weigh fifteen tons
(13,600 kg), and would have
been 8 ft (2.4 m) tall.

Babbages Analytical
Engine
- since the Difference Engine
was not fully completed that time,
Babbage designed a more
powerful mechanical computing
engine which is the Analytical
Engine. This engine marks the
transition from mechanised
arithmetic to fully fledged general
purpose computation.

Ada Augusta Lovelace Byron


(1815 - 1852)
Augusta Ada Byron, Lady
Lovelace, the daughter of the
illustrious poet, Lord Byron born in
year 1815. Ada worked with Babbage.
Ada suggested to Babbage, writing a
plan for how the analytical engine
might calculate Bernoulli numbers;
she wrote a series of Notes where
she demonstrated a sequence of
instructions she had prepared for the
analytical engine.

Ada Lovelace, was an English mathematician and


writer chiefly known for her work on Charles
Babbage's early mechanical general-purpose
computer, the Analytical Engine.
Ada met Babbage at a party in 1833 when she was
seventeen and was entranced when Babbage
demonstrated the small working section of the Engine
to her.
Her notes on the engine include what is recognized as
the first algorithm intended to be carried out by a
machine.

Because of this, she is often regarded as the first


computer programmer.
Charles Babbage realized that because of her insight
and new innovations, Ada Lovelace considered to be
the worlds first programmer in her honor in the late
1900.
And a software language developed by the U.S
Department was named ADA

Computer Language
A computer language is a set of rules and
conventions used to convey the information
to a computer.

Machine Language
The native tongue of a computer is the
Machine Language. Each Machine Language
instruction is a binary string of 0s and 1s that
specifies an operation and identifies the
memory cells involved in that operation.

3 Types of Computer Languages


Low Level Language

High Level Language


Middle Level Language

Low-Level Language Language


In the Low Level Language, Machine
Language is still used by the computer as it
processes data, but Low Level Language
software first translate the specified operation
symbol onto its Machine Language
equivalent.

Example:
Assembly Language

High-Level Language
High Level Language is a programming
language where an instruction resembles
everyday language. Instructions are given to
a computer by using a convenient letters,
symbols or English text rather than by using
1s and 0s code that the computer
understands.
Example is Visual Basicetc.

Example:

Visual Basic

Difference between the High Level


Language and the other two.
The main difference between the High Level
Language and the other two are that High
Level Language is much easier and
understandable by a human being and the
second difference is that in High Level
Language one instruction can perform
several machine level instructions.

Introduction to
C Language

What is C language:C

is mother language of all programming


language.

compilers can generates amazingly fast code.

Its

syntax makes it easy to write programs that


are modular and therefore they are easy to
understand and maintain.

It

is also called mid level programming language.

History of C language:C

programming language was developed in 1970s


by Dennis Ritchie at bell laboratories of
AT&T(American Telephone & Telegraph), located in
U.S.A.

Dennis
It

Ritchie is known as founder of C language.

was developed to be used in UNIX Operating


system.

Features of C Language:There are many features of c language are given below.


1) Simple
2) Machine Independent or Portable
3) Mid-level programming language
4) structured programming language
5) Rich Library
6) Memory Management
7) Fast Speed
8) Pointers
9) Recursion
10) Extensible

BASICS OF PROGRAMMING
In order to run the program you need to go through several
stages. These are:
1)

Source Program Type the text of the program into the


computer.

2)

Compiler Translate the program text into a form the


computer can use. Translates the whole source program into
machine language at once while the Interpreter translates
the source program into machine language line by line.

3)

Executable/Binary version of program Run the


translated program. The result of the translation or
compilation is the executable or binary version of the
program

Compiler
Compiler translates the whole source
program into machine language at once.
A large complex program that is responsible
for translating the source program into a form
that can be executed directly by the
computer.

NOTE:
If you are going to store the source file for future
alteration and development then you will need to
name the file in accordance with understood by
your compiler. Practically all C compilers expect
program source to be provided in files with
names ending in .c

C Data Types
Before a variable name (identifier) can be
used in a C program, it must be declared
explicitly, together with its corresponding data
type.
There are some restrictions in giving a name
to variables and constants.
Name can be composed of letters and
numbers, however the first character must be
a letter.

NOTE:
Keywords commands such as case, int, float,
if, do, for, etc.., cannot be used as variable or
constant names, because they are considered
as reserved words.

Basic Data Types of C


TYPE

FORMAT

MEANING

EXAMPLE(S)

Int

%d or %i

A whole number

(3, 7, +8, +9,


10000)

float

%f

A number with
decimal point

(5.8, 9.0, -5.6789,


+0.0032)

char

%c

A single letter,
symbol, or number
enclosed within
two single quotes

(B, r, 3 )

char

%s

A string in C is
considered as a
series if characters

(Ms., Hi!, 143,


I Love)

double

%f

For bigger or larger


numbers with a
decimal point

(12345678.123)

#include<> function
The line beginning with a hash sign # and
followed by include is called pre-pocessor.
It is a function which tells to the compiler to
include or to put Library file into C program.
Example Library file is the stdio.h

Structure:
#include <Library file>
Example:
#include<stdio.h>
#include<conio.h>

The printf function


printf function is to display the output(text,
numbersetc).
The printf is actually a function, just as main
is a function name. Since printf is a function,
therefore it is followed by parenthesis.

Semicolon ;
In a C program, the semicolon is a statement
terminator. That is, each individual statement
must be ended with a semicolon. It indicates
the end of one logical entity.

Structure:
main()
{
printf(Hello World!);
}
Output:
Hello World!

The scanf function


Every time we issue an input/output
command function in C program, we always
format the input/output variable.
For example, if we declare n as type of
int(integer) such as: int n; our input
formatting is scanf(%d, &n).

If we declare Area as type float(real) for


example: float Area; out input formatting is:
scanf(%f, &Area).
In our output statement printf, we use control
character or escape sequences. The most
popular and widely used is that backslash n
(\n).

Basic Operators of C
Arithmetic Operators
Symbol

Meaning

Addition

Subraction

Multiplication

Division

Modulus(Remainder)

First Program of C Language:#include <stdio.h>


#include <conio.h>
main(){
printf("Hello C Language");
getch();
}

Describe the C Program: #include

<stdio.h> includes the standard input output library


functions. The printf() function is defined in stdio.h .

#include

<conio.h> includes the console input output library


functions. The getch() function is defined in conio.h file.

main()

The main() function is the entry point of every


program in c language. The void keyword specifies that it returns
no value.

printf()

console.

getch()

The printf() function is used to print data on the

The getch() function asks for a single character. Until


you press any key, it blocks the screen.

Output of Program is:-

Hello C Language

Input output function: There

are two input output function of c language.


1) First is printf()
2) Second is scanf()
)printf() function is used for output. It prints the
given statement to the console.
)Syntax of printf() is given below:
)printf(format string,arguments_list);
)Format string can be %d(integer), %c(character),
%s(string), %f(float) etc.

scanf()

Function: is used for input. It


reads the input data from console.
scanf(format string,argument_list);
Note:-See

more example of input-output


function on:-www.javatpoint.com/printfscanf

scanf()

Function: is used for input. It


reads the input data from console.
scanf(format string,argument_list);
Note:-See

more example of input-output


function on:-www.javatpoint.com/printfscanf

Operators in C language: There are following types of operators to perform


different types of operations in C language.
1) Arithmetic Operators
2) Relational Operators
3) Shift Operators
4) Logical Operators
5) Bitwise Operators
6) Ternary or Conditional Operators
7) Assignment Operator
8) Misc Operator

Control statement in C language:1) if-else


2) switch
3) loops
4) do-while loop
5) while loop
6) for loop
7) break
8) continue

C if else statement: There are many ways to use if statement


in C language:
1) If statement
2) If-else statement
3) If else-if ladder
4) Nested if

if statement: In if statement is used to execute the


code if condition is true.
syntax:if(expression){
//code to be execute
}

If else statement: The if-else statement is used to execute


the code if condition is true or false.
Syntax:
if(expression){
//code to be executed if condition is true
}else{
//code to be executed if condition is false
}

If else-if ladder Statement: The if else-if statement is used to execute one code from
multiple conditions.
Syntax:
if(condition1){
//codetobeexecutedifcondition1istrue
}elseif(condition2){
//codetobeexecutedifcondition2istrue
}
elseif(condition3){
//codetobeexecutedifcondition3istrue
}
...
else{
//codetobeexecutedifalltheconditionsarefalse
}

if else-if ladder Statement: Syntax:


if(condition1){
//code to be executed if condition1 is true
}else if(condition2){
//code to be executed if condition2 is true
}
else if(condition3){
//code to be executed if condition3 is true
}
...
else{
//code to be executed if all the conditions are false
}

C Switch Statement: Syntax:


switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......
default:
code to be executed if all cases are not matched;
}

Loops in C language: Loops are used to execute a block of code


or a part of program of the program
several times.
Types of loops in C language: There are 3 types of loops in c language.
1) do while
2) while
3) for

do-while loop in C: It is better if you have to execute the code


at least once.
Syntax:do{
//code to be executed
}while(condition);

while loop in c language: It is better if number of iteration is not


known by the user.
Syntax:while(condition){
//code to be executed
}

For loop in C language: It is good if number of iteration is known


by the user.
Syntax:for(initialization;condition;incr/decr){
//code to be executed
}

C break statement: it is used to break the execution of loop


(while, do while and for) and switch case.
Syntax:jump-statement;
break;

Continue statement in C language: it is used to continue the execution of loop


(while, do while and for). It is used with if
condition within the loop.
Syntax:jump-statement;
continue;
Note:- you can see the example of above all
control statements on
www.javatpoint.com/c-if else.

Functions in C language: To perform any task, we can create


function. A function can be called many
times. It provides modularity and
code reusability.
Advantage of function:1) Code Resuability
2) Code optimization

Syntax

to declare function:return_type function_name(data_type para


meter...){
//code to be executed
}
Syntax to call function:variable=function_name(arguments...);

Call by value in C language:In call by value, value being passed to the function is locally
stored by the function parameter in stack memory location.
If you change the value of function parameter, it is
changed for the current function only. It will not change
the value of variable inside the caller method such as
main().

Example of call by value:#include <stdio.h>


#include <conio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
}
int main() {
int x=100;
clrscr();
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
getch();
return 0;
}

Output: Before function call x=100


Before adding value inside function
num=100
After adding value inside function
num=200
After function call x=100

Call by reference in C: In call by reference, original value is


modified because we pass reference
(address).

Example of call by Reference:#include <stdio.h>


#include <conio.h>
void change(int *num) {
printf("Before adding value inside function num=%d \n",*num);
(*num) += 100;
printf("After adding value inside function num=%d \n", *num);
}
int main() {
int x=100;
clrscr();
printf("Before function call x=%d \n", x);
change(&x);//passing reference in function
printf("After function call x=%d \n", x);
getch();
return 0;
}

Output: Before function call x=100


Before adding value inside function
num=100
After adding value inside function
num=200
After function call x=200

Recursion in C: A function that calls itself, and doen't perform any


task after function call, is know as tail recursion.
In tail recursion, we generally call the same
function with return statement.
Syntax:recursionfunction(){
recursionfunction();//calling self function
}

Array in C: Array

in C language is a collection or group of elements


(data). All the elements of array
are homogeneous(similar). It has contiguous memory
location.
Declaration of array: data_type array_name[array_size];
Eg: int marks[7];
Types of array:1) 1-D Array
2) 2-D Array

Advantage of array:1) Code Optimization


2) Easy to traverse data
3) Easy to sort data
4) Random Access

2-D Array in C: 2-d Array is represented in the form of


rows and columns, also known as matrix.
It is also known as array of arrays or list
of arrays.
Declaration of 2-d array: data_type array_name[size1][size2];

Initialization of 2-d array: int arr[3][4]={{1,2,3,4},{2,3,4,5},


{3,4,5,6}};

Das könnte Ihnen auch gefallen