CS Micro 1 Unit

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

UNIT 1

Algorithm An algorithm is a step-by-step set of instructions to solve a


problem or perform a task. Think of it as a recipe that tells you exactly what to
do, one step at a time.

Properties of an Algorithm

1. Finiteness: The algorithm must end after a certain number of steps.


2. Definiteness: Each step must be clear and unambiguous.
3. Input: An algorithm can have zero or more inputs to work with.
4. Output: An algorithm must produce at least one result.
5. Effectiveness: The steps should be simple enough that a person or
computer can perform them exactly and quickly.
6. Generality: The algorithm should work for a range of problems, not just
one specific case
Differences Between a Program and an Algorithm
• Algorithm: A plan or set of steps to solve a problem, written in a
way that anyone can understand.
• Program: The actual code written in a programming language
that a computer can execute.
• Algorithm: Conceptual and logical.
• Program: Practical and executable.
• Algorithm: To outline the solution to a problem.
• Program: To run the algorithm on a computer.
• Algorithm: Written in plain language or pseudocode (like a
recipe).
• Program: Written in a specific programming language (like C).
• Algorithm: High-level steps and logic.
• Program: Detailed code that includes the exact syntax of a
programming language.
• Algorithm: Can't be run directly by a computer.
• Program: Can be run by a computer.
UNIT 1
Program Development Cycle The Program Development Cycle is a series of
steps that programmers follow to develop a software program. It ensures that
the program is created systematically and meets the requirements efficiently.

Steps Involved in the Program Development Cycle

• What it is: Understanding and defining the problem that the


program is intended to solve.
• Activities: Discussing with stakeholders, gathering requirements,
and documenting the problem.
• What it is: Planning how the program will solve the problem.
• Activities: Creating algorithms, flowcharts, and pseudocode to
outline the solution.
• What it is: Writing the actual code in a programming language
based on the design.
• Activities: Translating the algorithms and design into a specific
programming language (e.g., C, Java).
• What it is: Checking the program to ensure it works correctly and
fixing any errors.
• Activities: Running the program with test data, identifying bugs,
and correcting them.
• What it is: Writing detailed information about the program to
help users and developers understand and use it.
• Activities: Creating user manuals, comments in the code, and
technical documentation.
• What it is: Installing the program and making it available for use.
• Activities: Setting up the program in the user environment,
configuring settings, and providing initial support.
• What it is: Updating and improving the program after it is
implemented.
• Activities: Fixing any new bugs, adding new features, and making
performance improvements.
UNIT 1

Syntax Error

A syntax error occurs when the code violates the rules of the programming
language. These errors are detected by the compiler or interpreter during the
compilation or interpretation phase. Syntax errors prevent the code from
being successfully compiled or executed.

Characteristics of Syntax Errors:

• Location: Detected by the compiler/interpreter.


• Detection Time: During compilation or interpretation.
• Examples:
• Missing semicolon at the end of a statement.

Logical Error

A logical error occurs when the program compiles and runs without issues, but
the output is not what was expected. This type of error is due to flaws in the
program's logic or algorithm, leading to incorrect results.

Characteristics of Logical Errors:

• Location: Detected during runtime.


• Detection Time: When the program produces incorrect results.
• Examples:
• Incorrect calculations or formula implementation.
An operating system (OS) is system software that manages computer
hardware and software resources and provides common services for computer
programs. There are various types of operating systems designed for different
purposes and platforms. Here are five examples of operating systems:

Examples of Operating Systems 1. Microsoft Windows A widely-used


operating system for personal computers, laptops, and servers.

1. macOS

2. Linux , Android, iOS


UNIT 1 Different Data Types
In the C programming language, data types are classifications that specify the
type of data a variable can hold. They define the size and type of data that can
be stored in a variable. Here are the primary data types in C:

1. Basic Data Types

1.1 Integer Types

• int: Represents whole numbers. Typically 4 bytes in size.


• short: Short integer, usually 2 bytes.
• long: Long integer, typically 4 or 8 bytes.
• long long: Extended long integer, usually 8 bytes.

1.2 Floating-Point Types

• float: Represents single-precision floating-point numbers. Typically 4


bytes.
• double: Represents double-precision floating-point numbers. Usually 8
bytes.
• long double: Extended precision floating-point numbers, typically 8 or
16 bytes.

1.3 Character Type

• char: Represents a single character. Typically 1 byte.

2. Derived Data Types

• Arrays: A collection of elements of the same type.


• Pointers: Variables that store the address of other variables.
• Structures (struct): Grouping of variables of different types under a
single name.
• Unions: Similar to structures, but all members share the same memory
location.

3. Void Type

• void: Represents the absence of any type. Commonly used in functions


to indicate no return value or no parameters.
UNIT 1

Operators in Programming Languages

. Operators are special symbols or keywords used in programming languages


to perform operations on operands (variables and values). They are
fundamental to building expressions and performing calculations,
comparisons, and logical operations.

Compiler in Programming Languages

A compiler is a special program that translates source code written in a high-


level programming language into machine code (binary code) that a
computer's processor can execute. The process of compilation involves several
stages, ensuring that the source code is syntactically and semantically correct
before generating the executable program.

Key Functions of a Compiler:

1. Lexical Analysis: The compiler scans the source code and converts it
into tokens, which are the smallest units of meaning (like keywords,
operators, identifiers).

2. Syntax Analysis: The compiler checks the tokens against the


grammatical rules of the programming language to ensure the code is
syntactically correct. This step builds a parse tree or abstract syntax tree.

3. Semantic Analysis: The compiler verifies the logical consistency and


correctness of the syntax tree. It checks for semantic errors, such as type
mismatches and undefined variables.

4. Intermediate Code Generation: The compiler translates the syntax tree


into an intermediate code that is independent of the machine language.

5. Optimization: The compiler optimizes the intermediate code to


improve efficiency and performance, reducing the resource usage and
execution time.

6. Code Generation: The compiler converts the optimized intermediate


code into machine code specific to the target processor architecture.
UNIT 1 List and explain the functions of various parts of computer hardware
and software. Ans: Computer Hardware:
1. Central Processing Unit (CPU): The CPU is often referred to as the brain of the
computer. It performs most of the calculations and executes instructions of a
computer program.
2. Random Access Memory (RAM): RAM is a type of volatile memory that provides
temporary storage for data and instructions that are currently being used by the
CPU.
3. Hard Disk Drive (HDD) or Solid State Drive (SSD): HDDs and SSDs are storage
devices used to store data and software permanently.
4. Motherboard: The motherboard is a circuit board that connects all the
components of a computer together.
5. Graphics Processing Unit (GPU): The GPU is responsible for rendering images,
videos, and animations
6. Power Supply Unit (PSU): The PSU converts AC power from an electrical outlet
into DC power that is required by the computer components.
7. Input and Output Devices: Input devices, such as keyboards and mice, allow
users to provide commands and data to the computer
Computer Software: 1. Operating System (OS): The OS is the fundamental
software that manages computer hardware and provides a user interface for
interacting with the system 2. Application Software: Application software refers
to programs that perform specific tasks for users. Examples include word
processors, web browsers, photo editors, and video players. 3. Device Drivers:
Device drivers are software components that allow the operating system to
communicate and interact with hardware devices. 4. Utilities: Utility software
includes programs that perform various maintenance and optimization tasks on
a computer. Examples include antivirus software, disk cleanup tools, backup
utilities, and system diagnostic tools. 5. Programming Languages: Programming
languages are used to write software applications and computer programs. They
provide a way for developers to write instructions and algorithms that the
computer can understand and execute. 6. Compiler and Interpreter: Compilers
and interpreters are software tools that convert high-level programming
languages into machine code or execute code directly. Compilers translate the
entire program in advance, while interpreters execute the program line by line.
UNIT 2 different types of loops with example

for Loop

The for loop is used when you know in advance how many times you want to
execute a block of code.

while Loop
The while loop is used when you want to execute a block of code repeatedly as long
as a condition is true. The condition is evaluated before executing the loop body.

do-while Loop

The do-while loop is similar to the while loop, but the condition is evaluated after
executing the loop body. This ensures that the loop body is executed at least once.

#include <stdio.h> #include <stdio.h> #include <stdio.h>

int main() { int main() { int main() {

int i; int i = 0; int i = 0;

for (i = 0; i < 5; i++) { while (i < 5) { do {

printf("Value of i: %d\n", i); printf("Value of i: %d\n", i); printf("Value of i: %d\n", i);

} i++; i++;

return 0; } } while (i < 5);

} return 0; return 0;

} }

You might also like