Learn C Programming in 13 Days — Quick Reference Notes
DAY 1 — Programming Fundamentals: PSEUDOCODE
Meaning of pseudocode and its role in problem analysis: Pseudocode is an informal, high-level description of a computer algorithm or other operating principle. It uses the structural conventions of a programming language, but is intended for human reading rather than machine execution. Its primary role is to help developers plan the logic of a program before writing actual code, making complex problems easier to understand, design, and debug. It bridges the gap between natural language descriptions and executable code.
Flowcharts used with pseudocode: Flowcharts are graphical representations of an algorithm's steps. They use standardized symbols (e.g., rectangles for processes, diamonds for decisions, ovals for start/end) to visually map the flow of control. Pseudocode and flowcharts often complement each other: pseudocode provides a textual, sequential description, while flowcharts offer a visual, step-by-step diagram, both aiding in problem analysis and design.
Operators: Symbols that perform operations on values and variables.
Arithmetic Operators: Used for mathematical calculations.
+(Addition): e.g.,-(Subtraction): e.g.,*(Multiplication): e.g.,/(Division): e.g.,%(Modulo): Returns the remainder of a division; e.g., equals .Assignment Operators: Used to assign a value to a variable.
<-(Assigns value to a variable): Common in pseudocode, e.g.,TOTAL <- QUANTITY * PRICE.=(Assigns value, especially in C-like pseudocode): e.g.,TOTAL = QUANTITY * PRICE.
Initial statements in pseudocode: Basic commands to perform fundamental operations.
ASSIGNMENT: Stores a value in a variable. Example:
SUM <- 0,NAME = "John Doe".INPUT: Reads data from an external source (e.g., user keyboard). Example:
INPUT (NUM1),INPUT (NAME, AGE).OUTPUT: Displays data or results to a destination (e.g., screen, printer). Example:
OUTPUT (RESULT),OUTPUT ("Hello World").
Variables and naming conventions: Variables are symbolic names for storing values. Effective naming is crucial for readability and maintainability.
Self-descriptive: Names should clearly indicate the variable's purpose (e.g.,
totalSalesinstead ofts).No gaps: Multi-word names should not contain spaces. Use camelCase (e.g.,
firstName) orsnake_case(e.g.,first_name). Pseudocode often uses capitalization for multi-word names.Start with CAPS for multi-word names (in pseudocode): Following a common pseudocode convention, the first letter of each word in a multi-word variable name is capitalized, e.g.,
GrandTotal,TaxRate.
Example concept: convert math expressions to pseudocode: Demonstrates how mathematical formulas are translated into operational steps.
Example: The Fahrenheit conversion formula
Becomes in pseudocode:
F <- (9.0 / 5) * C + 32orF = (9.0 / 5) * C + 32. Note the use of9.0to ensure floating-point division.
Relationship between natural language, pseudocode, and flowcharts as problem-solving tools: These three work in synergy. Natural language (English, etc.) helps to articulate the problem initially. Pseudocode structures the logical steps in a semi-formal way. Flowcharts provide a visual map of the algorithm's flow. Together, they form a comprehensive set of tools for designing, understanding, and communicating algorithmic solutions before actual coding begins, facilitating a systematic approach to problem-solving.
DAY 2 — The OUTPUT & INPUT STATEMENTS
OUTPUT: Statement used to display information, results, or messages to the user or a designated output device.
Purpose: To present the outcome of calculations, state prompts for user input, or provide general information.
Syntax concept in pseudocode:
PRINT(Variable)orDISPLAY(Expression). This statement instructs the program to show the current value stored inVariableor the result ofExpression.Strings in OUTPUT: When literal text needs to be displayed, it is enclosed in quotation marks.
Example:
PRINT( "Area of the circle = " )will output the exact phrase "Area of the circle = " to the screen. This is crucial for user guidance and readability.Combining text and variables:
PRINT( "The result is: ", RESULT )whereRESULTis a variable.
INPUT: Statement used to accept data entered by the user, typically via the keyboard, and store it into specified variables.
Purpose: To acquire necessary data from the user to be processed by the program.
Syntax:
INPUT( Variable )orREAD(Variable). The program pauses execution until the user enters a value, which is then assigned toVariable.Multiple values:
INPUT( A, B )allows the program to accept multiple values from the user, assigning them sequentially to variablesAandB.
Flowcharting fundamentals linked to input/output steps: In flowcharts, input and output operations are typically represented by a parallelogram symbol. The text inside the parallelogram describes the specific input or output action (e.g., "Enter radius", "Display Area"), indicating where data enters or leaves the program flow.
DAY 3 — OPERATORS and STATEMENTS in C
Identifiers: Names given to programming elements like variables, functions, arrays, and user-defined data types in C. They must follow specific rules:
Composed of letters (a-z, A-Z), digits (0-9), and the underscore character (
_).The first character must typically be a letter or an underscore (though starting with an underscore is often reserved for system names).
Case-sensitive:
myVariableis different frommyvariable.Cannot be a C keyword (e.g.,
int,for,while).
OPERATORS: Fundamental symbols that perform specific operations on operands.
Arithmetic operators:
+(addition),-(subtraction),*(multiplication),/(division),%(modulo - returns remainder).Assignment operator:
=(e.g.,x = 10;assigns the value 10 tox).
Statements end with a semicolon
;in C: Every complete executable statement in C (like variable declarations, assignment expressions, function calls, etc.) must be terminated by a semicolon. This acts as a statement separator.OUTPUT:
printf( format, variables );: Theprintffunction is used to print formatted output to the standard output device (console).format: A string literal containing text to be printed and format specifiers (placeholders for variables).variables: A comma-separated list of variables whose values are to be printed, matching the format specifiers.Format specifiers: Control how data types are displayed:
%dor%i: For signed decimal integers.%f: For floating-point numbers (single precisionfloator double precisiondouble).%s: For strings (character arrays).%c: For single characters.Example:
printf("Sum = %d and Average = %f\n", sum, avg);
INPUT:
scanf( "FormatString", &Variable );: Thescanffunction is used to read formatted input from the standard input device (keyboard).`