Fundamentals of Programming Lec-3.Pptx (1)
Fundamentals of Programming Lec-3.Pptx (1)
Fundamentals of Programming
Lecture 3 (Introduction to C)
2023/11/27
1
Generations of Computer Software
• Computer software has evolved over the years
through different generations.
• each marked by significant advancements in
technology.
• The concept of software generations is a way to
categorize and understand the progression of
software development.
2
First Generation (1940s-1950s)
• Machine Language and Assembly Language
• Programs were written in machine language, which is the
lowest-level programming language.
• Assembly language was introduced to make programming
easier by using mnemonic codes for machine instructions.
• Programs were executed directly on the hardware, and
there was a lack of high-level abstractions.
3
Second Generation (1950s-1960s)
• Assembly Language and Early High-Level
Languages.
• Assembly language continued to be used, but higher-level
programming languages like Fortran and COBOL were
introduced.
• These languages allowed for more abstraction and
improved programmer productivity.
• Batch processing systems became common.
4
Third Generation (1960s-1970s)
• High-Level Languages and Operating
Systems
• High-level programming languages like C and Pascal were
developed, providing even more abstraction.
• The concept of operating systems emerged, allowing
multiple programs to run concurrently.
• Time-sharing systems and the development of integrated
circuits occurred during this period.
5
Fourth Generation (1970s-Present)
• Integrated Software Development and
Microprocessors.
• he development of microprocessors and microcomputers
led to the personal computer revolution.
• Integrated development environments (IDEs) and
high-level languages like C++ and Java were introduced.
• Relational database management systems (RDBMS) and
graphical user interfaces (GUIs) became common.
6
Fifth Generation (1990s-Present)
Artificial Intelligence and Parallel Processing.
Focus on parallel processing and distributed computing.
Artificial Intelligence (AI) and expert systems gained
prominence.
Object-oriented programming languages like Python and
Ruby became popular.
Emphasis on natural language processing and
knowledge-based systems.
7
Sixth Generation (Present and Beyond)
• Advanced AI, Quantum Computing
• Ongoing advancements in AI, machine learning, and deep
learning.
• Exploration of quantum computing for solving complex
problems.
• Continued development of languages and tools for cloud
computing.
• Emphasis on automation, big data, and the Internet of
Things (IoT).
8
Introduction to Algorithms
• An algorithm is a set of instructions for solving a problem or
performing a task.
• Algorithms are used in many different fields, including
computer science, mathematics, engineering, and business.
• Algorithms are typically written in a programming language,
but they can also be expressed in other ways, such as
flowcharts or natural language.
• The goal of an algorithm is to be efficient, meaning that it
should use the least amount of time and resources possible to
solve the problem.
9
Common types of algorithms.
Sorting algorithms: These algorithms are used to sort a list of items
into a specific order, such as numerical order or alphabetical order.
Some common sorting algorithms include quicksort, mergesort, and
insertion sort.
Searching algorithms: These algorithms are used to find a specific item
in a list or data structure. Some common searching algorithms include
linear search, binary search, and hashing.
Graph algorithms: These algorithms are used to solve problems on
graphs, which are mathematical structures that represent relationships
between objects. Some common graph algorithms include Dijkstra's
algorithm and Prim's algorithm.
10
Programming Concepts
• Programming concepts are the fundamental building
blocks of computer programming.
• They provide the foundation for understanding how to
create instructions that computers can execute.
• These concepts are essential for any aspiring programmer
or anyone interested in understanding how software is
created.
11
Programming Concepts (con’t)
Variables: Variables are containers for storing data. They allow
programmers to represent information and use it throughout their
programs. Variables have names that identify them and data types that
specify the kind of information they can hold.
Data Types: Data types define the type of information that a variable
can store. Common data types include integers, floating-point
numbers, characters, strings, and booleans. Each data type has its own
set of operations and rules for manipulation.
12
Programming Concepts (con’t)
Operators: Operators are symbols that perform operations on data.
They allow programmers to manipulate data and perform calculations.
Common operators include arithmetic operators (+, -, *, /), comparison
operators (==, !=, <, >), logical operators (&&, ||, !), and assignment
operators (=).
Control Flow: Control flow determines the order in which instructions
are executed in a program. It allows programmers to make decisions
and repeat actions based on certain conditions. Common control flow
structures include if-else statements, loops (for loops, while loops), and
switch statements.
13
Programming Concepts (con’t)
Functions: Functions are reusable blocks of code that perform specific
tasks. They allow programmers to modularize their code and make it
easier to manage and reuse. Functions can take input parameters and
return output values.
Arrays: Arrays are collections of data items of the same type. They
allow programmers to store and access multiple data items efficiently.
Arrays are indexed using integers, and the index represents the position
of the item within the array.
14
Programming Concepts (con’t)
Objects and Classes: Object-oriented programming (OOP) is a
programming paradigm that revolves around objects and classes.
Objects are instances of classes, and they encapsulate data (attributes)
and behavior (methods). Classes define the blueprint for creating
objects and specify the attributes and methods they possess.
Input and Output: Input and output operations allow programs to
interact with the user and the external environment. Input operations
receive data from the user or other sources, while output operations
display data to the user or other destinations.
15
Programming Concepts (con’t)
Errors and Exception Handling: Errors are unexpected situations that
occur during program execution. Exception handling is the mechanism
for dealing with errors and preventing program crashes. It allows
programmers to catch errors, take corrective actions, and ensure
program stability.
Algorithms: Algorithms are sets of instructions for solving specific
problems. They provide a step-by-step approach for achieving a desired
outcome. Algorithms are essential in many aspects of programming,
from sorting data to performing complex calculations.
16
What is C?????
C is a general-purpose, imperative programming language that was
created in the 1970s by Dennis Ritchie at Bell Labs.
It is a very popular language and is used for a wide variety of
applications, including operating systems, device drivers, and
embedded systems.
C programmers need to be careful to write code that is correct and
secure, as mistakes can easily lead to security vulnerabilities or crashes.
17
How C Programming Language Works?
C is a compiled language. A compiler is a special tool that compiles the
program and converts it into the object file which is machine readable.
After the compilation process, the linker will combine different object
files and creates a single executable file to run the program.
18
Get Started With C
To start using C, you need two things:
19
IDE???
An Integrated Development Environment (IDE) is a software application
that provides comprehensive facilities for software development.
An IDE normally consists of at least a source-code editor, build
automation tools, and a debugger.
Some IDEs, such as IntelliJ IDEA, Eclipse, and Visual Studio, contain the
necessary compiler, interpreter, or both.
20
Key features of IDEs
• Source code editor: A source code editor is a program that allows
programmers to write and edit code. IDEs typically have advanced
features such as syntax highlighting, code completion, and error
checking.
• Build automation tools: Build automation tools are programs that
automate the process of compiling, linking, and packaging code.
IDEs typically have built-in build automation tools that can be used
to build projects with a single click.
• Debugger: A debugger is a program that allows programmers to
step through code and inspect variables to find and fix bugs. IDEs
typically have built-in debuggers that can be used to debug code.
21
Benefits of using an IDE
• Increased productivity: IDEs can help programmers to be more
productive by providing them with a set of tools that are all
integrated into a single environment. This can save programmers
time and effort, and it can also help them to write more bug-free
code.
• Improved code quality: IDEs can help programmers to write better
code by providing them with features such as syntax highlighting,
code completion, and error checking. These features can help
programmers to identify and fix errors early on in the development
process.
• Reduced development time: IDEs can help to reduce development
time by automating tasks such as compiling, linking, and packaging
code. This can free up programmers to focus on writing code and
testing their applications.
22
Popular IDEs
Visual Studio: Visual Studio is a popular IDE for developing Windows
applications. It is a powerful IDE that has a wide range of features.
IntelliJ IDEA: IntelliJ IDEA is a popular IDE for developing Java applications. It
is a cross-platform IDE that can be used on Windows, macOS, and Linux.
Eclipse: Eclipse is a popular IDE for developing Java applications. It is a free
and open-source IDE that is available for Windows, macOS, and Linux.
NetBeans: NetBeans is a popular IDE for developing Java and PHP
applications. It is a free and open-source IDE that is available for Windows,
macOS, and Linux.
Xcode: Xcode is a popular IDE for developing iOS and macOS applications. It
is included with the macOS operating system.
23
Getting Started with C
24
C Keywords
Keywords are predefined, reserved words used in programming that
have special meanings to the compiler. Keywords are part of the syntax
and they cannot be used as an identifier.
25
C Data Types
int
Integers are whole numbers that can have both zero, positive and
negative values but no decimal values. For example, 0, -5, 10
26
float and double
float and double are used to hold real numbers.
float salary;
double price;
27
char
Keyword char is used for declaring character type variables.
28
C Variables, Constants
In programming, a variable is a container (storage area) to hold data.
29
Rules for naming a variable
• A variable name can only have letters (both uppercase and
lowercase letters), digits and underscore.
• The first letter of a variable should be either a letter or an
underscore.
• There is no rule on how long a variable name (identifier) can be.
However, you may run into problems in some compilers if the
variable name is longer than 31 characters.
• You should always try to give meaningful names to variables. For
example: firstName is a better variable name than fn.
30
C Output
In C programming, printf() is one of the main output function. The function
sends formatted output to the screen.
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf("C Programming");
return 0;
}
31
How does this program work?
• All valid C programs must contain the main() function. The
code execution begins from the start of the main() function.
• The printf() is a library function to send formatted output to
the screen. The function prints the string inside quotations.
• To use printf() in our program, we need to include stdio.h
header file using the #include <stdio.h> statement.
• The return 0; statement inside the main() function is the "Exit
status" of the program. It's optional.
32
Integer Output
#include <stdio.h> • We use %d format specifier
to print int types. Here, the
int main() %d inside the quotations will
{ be replaced by the value of
int testInteger = 5; testInteger.
printf("Number = %d", testInteger);
return 0;
}
33
float and double Output
#include <stdio.h>
int main()
{
float number1 = 13.5;
double number2 = 12.4; "\n" is an escape sequence that
represents a newline character.
printf("number1 = %f\n", number1);
printf("number2 = %lf", number2);
return 0;
}
34
Print Characters
#include <stdio.h>
int main()
{
char chr = 'a';
printf("character = %c", chr);
return 0;
}
35
C Input
In C programming, scanf() is one of the commonly used function to take input from
the user. The scanf() function reads formatted input from the standard input such as
keyboards.
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
36
Format Specifiers for I/O
• %d for int
• %f for float
• %lf for double
• %c for char
37
C Comments
• In programming, comments are hints that a programmer can add to
make their code easier to read and understand.
#include <stdio.h>
int main() {
38
Types of Comments
There are two ways to add comments in C:
39
Thank you
40