Notes.docx
Notes.docx
7.2 Algorithm
7.2.1 define an algorithm
Define an Algorithm
An algorithm is a step-by-step sequence of instructions designed to perform a specific task
or solve a problem. It provides a clear and systematic approach that can be implemented
using a programming language or manually.
Input
Assembly language High-level language High-level language
Language
Feature Assembler Compiler Interpreter
c. Body of main()
The body is enclosed within curly braces { } and contains the program’s logic, including
variable declarations, function calls, loops, and other statements.
d. Global and Local Variables
● Global Variables: Declared outside all functions and accessible throughout the
program.
● Local Variables: Declared within a specific function or block and accessible only
within that scope.
Purposes:
1. Enhance code readability.
2. Document complex logic for future reference.
3. Provide context for variable or function usage.
4. Temporarily disable code for debugging.
8.4 Constants and Variables Differentiate Between a Constant and a Variable in C
8.4.1 differentiate between a constant and a variable in C programming language
Parameters:
It takes one argument, which is the character you want to print (the argument is usually
passed as an integer, which is the ASCII value of the character).
Return Value:
It returns the character that was printed as an unsigned char cast to an int.
Example:
2. puts()
The puts() function is used to print a string (a sequence of characters) to the screen, followed
by a newline character (\n).
● Syntax:
Parameters:
It takes a single argument: a pointer to a null-terminated string (a string ending with '\0').
Return Value:
It returns a non-negative number if the string is successfully printed
Example:
3. printf()
The printf() function is a more versatile function used for formatted output. You can print a
combination of strings, characters, integers, floating-point numbers, and more, by specifying
format specifiers.
Syntax:
Parameters:
The first argument is a format string that may contain format specifiers, which are
placeholders for variables that are printed. The remaining arguments are the values to be
printed.
Return Value:
It returns the number of characters printed, or a negative number if an error occurs.
Example:
Key Differences:
● putchar(): Used for printing a single character.
● puts(): Used for printing a string with a newline.
● printf(): Used for formatted output, allowing you to print different types of data with
specific formats.
9.1.2 write a C program containing the following data types and format specifiers:
a. decimal
b. integer
c. float (decimal notation)
d. float (exponential notation)
e. char
f. long int
g. string
9.1.3 write a C program that uses input functions scanf( ), getch( ), getche( ), getchar( )
and gets( ) function;
1. getch()
● Purpose: Reads a single character from the keyboard without displaying it on the
screen (no echo).
● Header File: <conio.h> (may not be available on all systems).
● Usage: char ch = getch();
● Example:
● Key Notes:
o Useful in scenarios where you need hidden input (e.g., passwords).
o Does not require pressing Enter to complete input.
2. getche()
● Purpose: Reads a single character from the keyboard and displays it on the screen
(echoes input).
● Header File: <conio.h> (may not be available on all systems).
● Usage: char ch = getche();
● Example:
Key Notes:
● Similar to getch(), but shows the character on the screen.
● Input does not require pressing Enter.
3. getchar()
● Purpose: Reads a single character from the standard input and returns it.
● Usage: char ch = getchar();
● Example:
● Key Notes:
o Input is displayed on the screen.
o Requires pressing Enter to complete input.
gets()
● Purpose: Reads a string (including spaces) from the standard input.
● Usage: gets(string);
● Example:
Key Notes:
● Reads a line of text until a newline (\n) is encountered.
Escape
Name Description
Sequence
\n New Line It moves the cursor to the start of the next line.
\r Carriage Return It moves the cursor to the start of the current line.
It inserts some whitespace to the left of the cursor and moves the
\t Horizontal Tab
cursor accordingly.
int main() {
int a = 10, b = 5;
int sum, diff, prod, quotient, remainder;
// Arithmetic Operations
sum = a + b;
diff = a - b;
prod = a * b;
quotient = a / b;
remainder = a % b;
// Display Results
printf("Sum: %d\n", sum);
printf("Difference: %d\n", diff);
printf("Product: %d\n", prod);
printf("Quotient: %d\n", quotient);
printf("Remainder: %d\n", remainder);
return 0;
}
9.2.2 convert given arithmetic expression into C language code
Given Arithmetic Expression:
( (a + b) * (c - d) ) / e
#include <stdio.h>
int main() {
int a = 10, b = 20;
// Assignment Operator
a = b; // a gets the value of b
printf("a = %d\n", a);
a -= b; // a = a - b
printf("a -= b: %d\n", a);
a *= b; // a = a * b
printf("a *= b: %d\n", a);
a /= b; // a = a / b
printf("a /= b: %d\n", a);
a %= b; // a = a % b
printf("a %%= b: %d\n", a);
return 0;
}
9.2.5 use the increment (++) and decrement ( --) operators in a C program
#include <stdio.h>
int main() {
int a = 5;
// Increment operator
printf("a before increment: %d\n", a);
a++; // Post-increment
printf("a after increment: %d\n", a);
// Decrement operator
printf("a before decrement: %d\n", a);
a--; // Post-decrement
printf("a after decrement: %d\n", a);
return 0;
}
9.2.6 use the following relational operators in a C program:
a. less than (<)
b. greater than ( > )
c. less than or equal to (<=)
d. greater than or equal to ( >= )
e. equal to (= =)
f. not equal to (! =)
#include <stdio.h>
int main() {
int x = 10, y = 20;
return 0;
}
9.2.7 use the following logical operators in a C program:
a. AND (&&)
b. OR (||)
c. NOT (!)
#include <stdio.h>
int main() {
int a = 5, b = 10;
// AND operator
printf("a > 3 && b < 15: %d\n", a > 3 && b < 15);
// OR operator
printf("a > 3 || b > 15: %d\n", a > 3 || b > 15);
// NOT operator
printf("!(a > 3): %d\n", !(a > 3));
return 0;
}
9.2.8 differentiate between the assignment operator (=) and equal to operator (= =)
● Assignment Operator (=) is used to assign a value to a variable.
o Example: x = 5;
● Equal To Operator (==) is used to compare two values.
o Example: x == 5; (checks if x is equal to 5)
statement.
10.1.8 write C programs for the problems mentioned in 7.2.3 involving the use of if-else
if statement.
10.1.9 write the structure of switch statement.
Advantages Disadvantages
Easy to read and understand for Limited to checking equality of constants (does not
multiple conditions. handle ranges or logical operators).
int main() {
int choice;
printf("Choose an option (1-3): ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("You chose option 1.\n");
break;
case 2:
printf("You chose option 2.\n");
break;
case 3:
printf("You chose option 3.\n");
break;
default:
printf("Invalid option.\n");
}
return 0;
}
Computer Logic and Gates
12.1 Data Representation
12.1.1 show the binary data representation using binary pulses i.e. 0/low/ off and 1/
high/ on.
Binary Data Representation
● Computers represent data using binary pulses, which are sequences of 0s and 1s.
o 0 (Low/Off): Represents the absence of a signal or a low voltage state.
o 1 (High/On): Represents the presence of a signal or a high voltage state.
● Example:
o A binary sequence, such as 1010, represents alternating on and off states. This
is essential for data storage, processing, and transmission.
14.1.3 differentiate among the types of hackers, i.e. script kiddie, white
hat hackers, black hat hackers, grey hat hacker, green hat, hackers, red hat hackers, blue hat
hackers
Differentiate Among Types of Hackers
Type of
Description Intent
Hacker
14.1.4 differentiate among the types of malware, i.e. virus, worm, adware, spyware, Trojan
horses
Type of
Description How It Spreads Effects/Intent
Malware
Adware Software designed to Bundled with legitimate Annoys users with ads,
display advertisements, software or installed tracks browsing activity,
Type of
Description How It Spreads Effects/Intent
Malware
Purpose To confirm "Who are you?" To confirm "What are you allowed to do?"
Purpose To confirm "Who are you?" To confirm "What are you allowed to do?"
14.2 Computer Viruses 14.2.1 discuss the ways in which a malware can spread via:
a. infected flash drives/ CD’s
b. pirated software
c. local area network
d. internet
e. e-mail attachments
14.2.1 Ways Malware Can Spread
14.2.3 Identify the precautions to safeguard computer systems against the ways through
which malware can spread mentioned in SLO14.2.1
Precautions to Safeguard Computer Systems
Method Precautions
c. Local Area Network - Restrict access to shared folders and enforce network security
(LAN) policies.
14.3.2 differentiate between Two Factor Authentication (2FA) and Multifactor Authentication
(MFA)
Aspect Two-Factor Authentication (2FA) Multifactor Authentication (MFA)