CSE – 1101: Computer Programming
[3.0 Credits]
Introduction to Programming
Languages
Prof. Md. Alamgir Hossain, CSE, Faridpur Engineering College
Computer Fundamentals (Reviews)
What is a Computer?
Hardware (CPU, RAM, HD, Keyboard, Mouse, Monitor, etc.)
Software
System Software (Operating System, Compilers)
Application Software
Block of a Computer:
Input Processing Output
History of Computers:
The early inventions was Chinese abacus.
Charles Babbage’s “Analytical engine” (1834).
MAH, CSE, FEC
Computer Fundamentals (Reviews)
History & Generations:
First Generation (1937 – 1953)
Second Generation (1954 – 1962)
Third Generation (1963 – 1972)
Fourth Generation (1972 – 1984)
Fifth Generation (1984 – 1990)
Sixth Generation (1990 – till date)
Classification of Digital Computes
PC, Mainframe Computers, Minicomputers, Supercomputers
Computers in Society:
Advantages and Disadvantages
MAH, CSE, FEC
Programming Languages
Computer Language is used by programmer to communicate with
computers.
Types of Programming Languages: (User End)
High Level Language
Simplicity
Portability
C, Fortran, Java
Low Level Language
Difficult
Machine dependence
Machine language
Mid Level Language
C (sometime called)
MAH, CSE, FEC
Programming Languages (Cont.)
Types of programming languages (Structure)
Procedural programming languages.
A procedural language follows a sequence of statements or commands in order to
achieve a desired output.
Functional programming languages.
Object-oriented programming languages (OOP).
Scripting languages.
Logic programming languages.
MAH, CSE, FEC
Program Characteristics
Integrity
The accuracy of the calculations
Clarity
The overall readability of the program, with particular emphasis on its underlying
logic.
Simplicity
The clarity and accuracy of a program are usually enhanced by keeping things as
simple as possible.
Efficiency
Concerned with execution speed and efficient memory utilization.
Modularity
Programs can be broken down into a series of identifiable subtasks.
Generality
Program to be as general as possible, within reasonable limits.
MAH, CSE, FEC
Structured Programming
Encompasses a number of methodologies to produce good quality
design and code, which can be
Easily understood
Tested
Debugged
Modified
Maintained in future
Main Principles
Program design (top-down or button-up approach)
Decomposition of program into components
Structuring of control flow (Sequence, Selection, Iteration)
MAH, CSE, FEC
Basic of a C Program
C program consists of functions (or modules).
Build-in functions
User define functions
One function’s name must be main.
The program always start executing from main function.
All other functions must be called (directly/indirectly) into the main function.
Any other function definitions must be defined ahead or after main function.
Each function must contain:
Function Heading (return type, function name, arguments (optional) enclosed in
parentheses)
Function Body (Declarations, statements)
Build-in functions file name must be included before main function.
Examples: printf(), scanf(), sqrt(), round() etc.
MAH, CSE, FEC
Structure of a C Program
General form of a C Program:
#incluede<header file name>
int main(void)
{
statements;
return 0;
}
MAH, CSE, FEC
Develop A Program
Analyze the Problem
(inputs, outputs and processing)
Design
(algorithm, flow chart)
Coding
(programming languages)
Testing & Debugging
( compile)
Running
(verify its correctness)
Documentation
(further use)
MAH, CSE, FEC
Introduction to C Programming
C character Set
All uppercase & lowercase letters (A to Z & a to z)
The digits (0 to 9)
Special characters (+ , *, % , # etc.)
Keywords
Certain reserved words (int , for , char , if )
Only 32 standard keywords
Some compilers may include more 8 keywords
Identifiers
Names that are given to various program elements (variables, function)
Rules to give identifiers name
The first character must be a letter
Both uppercase and lowercase letters are permitted
The underscore character ( _ ) can also be included
The keywords cannot be used
MAH, CSE, FEC
Data Types
int
Integer quantity
2 bytes or one word (varies from one compiler to another)
char
Single character
1 byte
float
Floating-point number (number containing a decimal point)
2 words (4 bytes)
double
Double-precision floating-point number
4 words (8 bytes)
MAH, CSE, FEC
C Fundamentals
Constants:
Integer, unsigned, long, floating-point etc.
Escape Sequences:
\n, \a, \\, \t etc.
Variables:
All variables must be declared before use.
int a, b; char flag; float root1, root2;
MAH, CSE, FEC
C Fundamentals (cont.)
Expression:
Consist of constant, variable or other element, interconnected by one
or more operators.
a + b; z = (x + y)/2.o;
Statements:
Expression statements, Compound statements, Control statements
Symbolic Constants:
#define name text ( #define PI 3.1415)
MAH, CSE, FEC
Algorithm
Algorithm:
A procedure (set of instructions) used for solving a problem or
performing a computation.
step-by-step method for solving a problem.
Qualities of a Good Algorithm:
Input and output should be defined precisely.
Each step in the algorithm should be clear and unambiguous.
Algorithms should be most effective among many different ways to
solve a problem.
An algorithm should be written in such a way that it can be used in
different programming languages.
MAH, CSE, FEC
Algorithm Example
Algorithm: Add two numbers entered by the user
Step 1: Start
Step 2: Declare variables A, B and Sum.
Step 3: Read values A and B
Step 4: Add A and B and assign the result to Sum.
Sum = A + B
Step 5: Display Sum.
Step 6: Stop.
MAH, CSE, FEC
Flow Chart
Flow Chart:
A graphical representation of solving problems using pre-define symbols.
A flowchart is a diagram that represents an algorithm.
Symbols Used:
MAH, CSE, FEC
Flow Chart Example
The Average Of Two Numbers Check Input Number Odd Or Even
MAH, CSE, FEC
Simple Problems
Write a C program to find the average of three integer numbers,
taking inputs from keyboard and show the output on the
computer monitor.
#include<stdio.h>
int main()
{
int x, y, z;
float avg;
printf("Enter three integer numbers:");
scanf("%d%d%d",&x,&y,&z);
avg = (x+y+z)/3.0;
printf("\nAverage = %.2f\n",avg);
return 0;
}
MAH, CSE, FEC
Simple Problems (cont.)
Write a C program to calculate the average of three numbers
(taking inputs from keyboard) and show the output as nearest
integer.
#include<stdio.h>
#include<math.h>
int main()
{
float x, y, z, avg;
printf("Enter three numbers:");
scanf("%f%f%f",&x,&y,&z);
avg = (x+y+z)/3.0;
printf("\nAverage = %.0f\n", round(avg));
return 0;
}
MAH, CSE, FEC
The End