Introduction to C
Programming
•Reporter
Created By AI
Introduction to Computer Systems
Variables and Arithmetic Expressions
Symbolic Constants and Scope
Operators in C
Type Conversions
Table of
Contents
Control Flow Statements
01.
02.
03.
04.
05.
06.
Introduction to
Computer Systems
01
Central Processing Unit (CPU),
Memory (RAM), Storage (Hard drive,
SSD), Input/Output devices
(Keyboard, Mouse, Monitor).
Hardware Components
The CPU executes instructions provided
by the software, using memory to store
data and interacting with I/O devices.
How Hardware and Software
Interact
Operating System (Windows, macOS,
Linux), Applications (Word
processors, Web browsers,
Compilers).
Software Components
What is a Computer?
Bits and Bytes
Computers use binary (0s and 1s) to
represent data.
Binary Representation
A byte consists of 8 bits and is a fundamental
unit of data; Larger units: Kilobyte (KB),
Megabyte (MB), Gigabyte (GB), Terabyte (TB).
Bytes and Data Sizes
01
Compilers translate high-level code into machine code;
Interpreters execute high-level code line by line.
Compilers and Interpreters
02
High-level languages (C, Java, Python) are
easier for humans to read and write; Low-
level languages (Assembly) are closer to
machine code.
High-Level vs. Low-Level Languages
03 C is a powerful, efficient, and versatile
language widely used in system
programming and embedded systems;
Forms the basis for many other
languages.
Why C?
Introduction to Programming Languages
Variables and
Arithmetic
Expressions
02
Declaring Variables
Specify the data type (e.g., int, float, char) and
name of the variable; Example: `int age;`
Definition of a Variable
A variable is a named storage location in memory
that can hold a value; Used to store data that can be
modified during program execution.
Initializing Variables
Assign an initial value to a variable when it is
declared; Example: `int age = 20;`
What is a Variable?
Data Types and Sizes
Character Type
`char` (typically 1 byte), used to store single
characters; Example: `char grade = 'A';`
Floating-Point Types
`float` (typically 4 bytes), `double` (typically 8 bytes);
Used to store decimal numbers.
Integer Types
`int` (typically 4 bytes), `short` (typically 2 bytes),
`long` (typically 8 bytes); `unsigned int` for non-
negative integers.
Arithmetic Operators
Basic Operators
Addition (+), Subtraction (-),
Multiplication (), Division (/),
Modulus (%).
01
Operator Precedence
Multiplication and division have
higher precedence than
addition and subtraction; Use
parentheses to control the
order of evaluation.
02
Examples of Arithmetic
Expressions
`int x = 10 + 5 2; // x = 20`; `float
y = (10 + 5) / 2.0; // y = 7.5`
03
Symbolic Constants
and Scope
03
What is a Symbolic Constant?
Definition of a
Symbolic Constant
01
A symbolic constant is a
name given to a value that
cannot be changed during
program execution; Makes
code more readable and
maintainable.
Using `#define`
02
The `#define` preprocessor
directive is used to define
symbolic constants;
Example: `#define PI
3.14159`
Using `const` Keyword
03
The `const` keyword can also
be used to declare
constants; Example: `const
int MAX_VALUE = 100;`
Scope of Variables
Local Variables
Declared inside a function and are
only accessible within that function.
Global Variables
Declared outside any function and
are accessible throughout the
entire program; Use with caution,
as they can make code harder to
maintain.
Block Scope
Variables declared inside a block
(e.g., inside an `if` statement or
loop) are only accessible within that
block.
Example: Calculating Circle Area
Code Snippet
#include <stdio.h>
#define PI 3.14159
int main() {
float radius = 5.0;
float area = PI *
radius * radius;
printf("Area = %f
n", area);
return 0;
}
Example: Calculating Circle Area
Uses symbolic constant PI and local variable radius to
calculate and print the area of a circle.
Explanation
Operators in C
04
Increment and Decrement Operators
Examples
Postfix and Prefix Operators
`x++` (postfix): use the current value of x, then
increment; `++x` (prefix): increment x, then use
the new value.
Increment and Decrement Operators
Examples
int x = 5;
printf("%dn", x++); // Output:
5, x becomes 6
printf("%dn", ++x); // Output:
7, x becomes 7
Bitwise Operators
AND, OR, XOR, NOT
`&` (AND), `|` (OR), `^` (XOR), `~` (NOT); Used for
manipulating individual bits of an integer.
Shift Operators
`<<` (left shift), `>>` (right shift); Used for shifting bits
to the left or right.
Examples
Bitwise Operators
Examples
unsigned int x = 5; // 00000101
in binary
unsigned int y = 3; // 00000011
in binary
printf("%un", x & y); // Output:
1 (00000001)
printf("%un", x << 1); //
Output: 10 (00001010)
`=` assigns the value on the right to
the variable on the left; Example:
`int x = 10;`
Simple Assignment
01
`+=`, `-=`, `=`, `/=`, `%=`; Example: `x
+= 5` is equivalent to `x = x + 5`
Compound Assignment
02
Examples
03
Assignment Operators and Expressions
Assignment Operators and Expressions
Examples
int x = 10;
x += 5; // x
is now 15
x *= 2; // x
is now 30
Conditional Expressions
Ternary Operator
`condition ? expression1 :
expression2`; If the condition is
true, expression1 is evaluated;
otherwise, expression2 is
evaluated.
01
Example
02
Conditional Expressions
Example
int age = 20;
printf("%sn", (age >= 18) ? "Adult" :
"Minor"); // Output: Adult
Operator Precedence and Order of Evaluation
Precedence Table
Operators are evaluated based on
their precedence (e.g., multiplication
before addition); Use parentheses to
override precedence.
Examples
01
02
03
Associativity
If operators have the same
precedence, associativity determines
the order of evaluation (left-to-right
or right-to-left).
Operator Precedence and Order of Evaluation
Examples
int x = 2 + 3 * 4; // x = 14
(multiplication first)
int y = (2 + 3) * 4; // y = 20
(parentheses first)
Type Conversions
05
Implicit Type Conversion
Automatic conversion of data types by
the compiler; Usually done when
performing operations between different
data types.
What is Implicit Type Conversion?
Examples
Implicit Type Conversion
Examples
int x = 10;
float y = x + 5.5; // x is
implicitly converted to float
printf("%fn", y); // Output:
15.500000
Implicit Type Conversion
Lower-ranked types are promoted to higher-ranked
types (e.g., `int` to `float`, `float` to `double`).
Rules for Implicit Conversion
Explicit Type Conversion (Casting)
What is Explicit Type Conversion?
Manually converting a value from one type to another
using the cast operator.
Syntax
`(type) expression`; Example: `(int) 3.14159`
Examples
Explicit Type Conversion (Casting)
Examples
float x = 3.14159;
int y = (int) x; // y
= 3 (truncation)
printf("%dn", y);
Data Type Sizes
The `sizeof` operator returns the size (in
bytes) of a data type or variable.
`sizeof` Operator
Examples
Data Type Sizes
Examples
#include <stdio.h>
int main() {
printf("Size of int: %lu bytesn",
sizeof(int));
printf("Size of float: %lu bytes
n", sizeof(float));
printf("Size of double: %lu bytes
n", sizeof(double));
return 0;
}
Control Flow
Statements
06
`if` and `if-else` Statements
Basic `if` Statement
Executes a block of code if a
condition is true; `if (condition) { /
code / }`
`if-else` Statement
Executes one block of code if a condition is
true and another block if it is false; `if
(condition) { / code if true / } else { / code if
false / }`
Examples
`if` and `if-else` Statements
Examples
int age =
20;
if (age >=
18) {
printf("Adul
tn");
} else {
printf("Mino
rn");
}
`else-if` Statements
Chaining Multiple
Conditions
Allows you to test multiple
conditions in sequence; `if
(condition1) { / code / } else if
(condition2) { / code / } else { /
code / }`
01
Examples
02
`else-if` Statements
Examples
int score = 85;
if (score >= 90)
{
printf("A
n");
} else if (score
>= 80) {
printf("B
n");
} else if (score
>= 70) {
printf("C
n");
} else {
printf("Fail
n");
}
`switch` Statement
Syntax
Using `switch` for Multiple Cases
Allows you to select one of several code blocks
based on the value of an expression.
`switch` Statement
Syntax
switch (expression) {
case value1: /*
code */ break;
case value2: /*
code */ break;
default: /* code */
}
`switch` Statement
Examples
int day = 3;
switch (day) {
case 1: printf("Monday
n"); break;
case 2: printf("Tuesday
n"); break;
case 3:
printf("Wednesdayn"); break;
default: printf("Other
dayn");
}
Loop Statements
07
`while` Loop
Executes a block of code repeatedly as
long as a condition is true; `while
(condition) { / code / }`
Basic `while` Loop
Examples
`while` Loop
Examples
int i = 0;
while (i <
5) {
printf("%d
n", i);
i++;
}
`for` Loop
Provides a more structured way to write
loops with initialization, condition, and
increment/decrement in one line; `for
(initialization; condition;
increment/decrement) { / code / }`
Basic `for` Loop
Examples
`for` Loop
Examples
for (int i = 0;
i < 5; i++) {
printf("%d
n", i);
}
Similar to `while` loop, but the code block is executed
at least once because the condition is checked at the
end; `do { / code / } while (condition);`
Basic `do-while` Loop
Examples
`do-while` Loop
`do-while` Loop
Examples
int i = 0;
do {
printf("%d
n", i);
i++;
} while (i <
5);
`break` Statement
Terminates the loop or
`switch` statement
immediately.
`continue`
Statement
Skips the rest of the
current iteration and
continues with the next
iteration.
`goto` Statement
Transfers control to a
labeled statement; Use
with caution.
Examples
`break`, `continue`, and `goto`
`break`, `continue`, and `goto`
Examples
for (int i = 0; i < 10; i++) {
if (i == 5) break; // Exit
loop
if (i % 2 == 0) continue; //
Skip even numbers
printf("%dn", i);
}
Conclusion
08
Importance of C Programming
Highlight the significance of C in various
fields.
Recap
Briefly review the main topics covered
(variables, operators, control flow, loops).
Summary of Key Concepts
Next Steps
Recommend books, online courses, and
websites for further study.
Further Learning Resources
Encourage students to practice coding to
reinforce their understanding.
Practice Exercises
Q & A
Address questions and clarify any doubts about the
topics covered.
Open the floor to Questions
Thank you for
listening.
Reporter

programming for problem solving unit-1 aippt

  • 1.
  • 2.
    Introduction to ComputerSystems Variables and Arithmetic Expressions Symbolic Constants and Scope Operators in C Type Conversions Table of Contents Control Flow Statements 01. 02. 03. 04. 05. 06.
  • 3.
  • 4.
    Central Processing Unit(CPU), Memory (RAM), Storage (Hard drive, SSD), Input/Output devices (Keyboard, Mouse, Monitor). Hardware Components The CPU executes instructions provided by the software, using memory to store data and interacting with I/O devices. How Hardware and Software Interact Operating System (Windows, macOS, Linux), Applications (Word processors, Web browsers, Compilers). Software Components What is a Computer?
  • 5.
    Bits and Bytes Computersuse binary (0s and 1s) to represent data. Binary Representation A byte consists of 8 bits and is a fundamental unit of data; Larger units: Kilobyte (KB), Megabyte (MB), Gigabyte (GB), Terabyte (TB). Bytes and Data Sizes
  • 6.
    01 Compilers translate high-levelcode into machine code; Interpreters execute high-level code line by line. Compilers and Interpreters 02 High-level languages (C, Java, Python) are easier for humans to read and write; Low- level languages (Assembly) are closer to machine code. High-Level vs. Low-Level Languages 03 C is a powerful, efficient, and versatile language widely used in system programming and embedded systems; Forms the basis for many other languages. Why C? Introduction to Programming Languages
  • 7.
  • 8.
    Declaring Variables Specify thedata type (e.g., int, float, char) and name of the variable; Example: `int age;` Definition of a Variable A variable is a named storage location in memory that can hold a value; Used to store data that can be modified during program execution. Initializing Variables Assign an initial value to a variable when it is declared; Example: `int age = 20;` What is a Variable?
  • 9.
    Data Types andSizes Character Type `char` (typically 1 byte), used to store single characters; Example: `char grade = 'A';` Floating-Point Types `float` (typically 4 bytes), `double` (typically 8 bytes); Used to store decimal numbers. Integer Types `int` (typically 4 bytes), `short` (typically 2 bytes), `long` (typically 8 bytes); `unsigned int` for non- negative integers.
  • 10.
    Arithmetic Operators Basic Operators Addition(+), Subtraction (-), Multiplication (), Division (/), Modulus (%). 01 Operator Precedence Multiplication and division have higher precedence than addition and subtraction; Use parentheses to control the order of evaluation. 02 Examples of Arithmetic Expressions `int x = 10 + 5 2; // x = 20`; `float y = (10 + 5) / 2.0; // y = 7.5` 03
  • 11.
  • 12.
    What is aSymbolic Constant? Definition of a Symbolic Constant 01 A symbolic constant is a name given to a value that cannot be changed during program execution; Makes code more readable and maintainable. Using `#define` 02 The `#define` preprocessor directive is used to define symbolic constants; Example: `#define PI 3.14159` Using `const` Keyword 03 The `const` keyword can also be used to declare constants; Example: `const int MAX_VALUE = 100;`
  • 13.
    Scope of Variables LocalVariables Declared inside a function and are only accessible within that function. Global Variables Declared outside any function and are accessible throughout the entire program; Use with caution, as they can make code harder to maintain. Block Scope Variables declared inside a block (e.g., inside an `if` statement or loop) are only accessible within that block.
  • 14.
    Example: Calculating CircleArea Code Snippet #include <stdio.h> #define PI 3.14159 int main() { float radius = 5.0; float area = PI * radius * radius; printf("Area = %f n", area); return 0; }
  • 15.
    Example: Calculating CircleArea Uses symbolic constant PI and local variable radius to calculate and print the area of a circle. Explanation
  • 16.
  • 17.
    Increment and DecrementOperators Examples Postfix and Prefix Operators `x++` (postfix): use the current value of x, then increment; `++x` (prefix): increment x, then use the new value.
  • 18.
    Increment and DecrementOperators Examples int x = 5; printf("%dn", x++); // Output: 5, x becomes 6 printf("%dn", ++x); // Output: 7, x becomes 7
  • 19.
    Bitwise Operators AND, OR,XOR, NOT `&` (AND), `|` (OR), `^` (XOR), `~` (NOT); Used for manipulating individual bits of an integer. Shift Operators `<<` (left shift), `>>` (right shift); Used for shifting bits to the left or right. Examples
  • 20.
    Bitwise Operators Examples unsigned intx = 5; // 00000101 in binary unsigned int y = 3; // 00000011 in binary printf("%un", x & y); // Output: 1 (00000001) printf("%un", x << 1); // Output: 10 (00001010)
  • 21.
    `=` assigns thevalue on the right to the variable on the left; Example: `int x = 10;` Simple Assignment 01 `+=`, `-=`, `=`, `/=`, `%=`; Example: `x += 5` is equivalent to `x = x + 5` Compound Assignment 02 Examples 03 Assignment Operators and Expressions
  • 22.
    Assignment Operators andExpressions Examples int x = 10; x += 5; // x is now 15 x *= 2; // x is now 30
  • 23.
    Conditional Expressions Ternary Operator `condition? expression1 : expression2`; If the condition is true, expression1 is evaluated; otherwise, expression2 is evaluated. 01 Example 02
  • 24.
    Conditional Expressions Example int age= 20; printf("%sn", (age >= 18) ? "Adult" : "Minor"); // Output: Adult
  • 25.
    Operator Precedence andOrder of Evaluation Precedence Table Operators are evaluated based on their precedence (e.g., multiplication before addition); Use parentheses to override precedence. Examples 01 02 03 Associativity If operators have the same precedence, associativity determines the order of evaluation (left-to-right or right-to-left).
  • 26.
    Operator Precedence andOrder of Evaluation Examples int x = 2 + 3 * 4; // x = 14 (multiplication first) int y = (2 + 3) * 4; // y = 20 (parentheses first)
  • 27.
  • 28.
    Implicit Type Conversion Automaticconversion of data types by the compiler; Usually done when performing operations between different data types. What is Implicit Type Conversion? Examples
  • 29.
    Implicit Type Conversion Examples intx = 10; float y = x + 5.5; // x is implicitly converted to float printf("%fn", y); // Output: 15.500000
  • 30.
    Implicit Type Conversion Lower-rankedtypes are promoted to higher-ranked types (e.g., `int` to `float`, `float` to `double`). Rules for Implicit Conversion
  • 31.
    Explicit Type Conversion(Casting) What is Explicit Type Conversion? Manually converting a value from one type to another using the cast operator. Syntax `(type) expression`; Example: `(int) 3.14159` Examples
  • 32.
    Explicit Type Conversion(Casting) Examples float x = 3.14159; int y = (int) x; // y = 3 (truncation) printf("%dn", y);
  • 33.
    Data Type Sizes The`sizeof` operator returns the size (in bytes) of a data type or variable. `sizeof` Operator Examples
  • 34.
    Data Type Sizes Examples #include<stdio.h> int main() { printf("Size of int: %lu bytesn", sizeof(int)); printf("Size of float: %lu bytes n", sizeof(float)); printf("Size of double: %lu bytes n", sizeof(double)); return 0; }
  • 35.
  • 36.
    `if` and `if-else`Statements Basic `if` Statement Executes a block of code if a condition is true; `if (condition) { / code / }` `if-else` Statement Executes one block of code if a condition is true and another block if it is false; `if (condition) { / code if true / } else { / code if false / }` Examples
  • 37.
    `if` and `if-else`Statements Examples int age = 20; if (age >= 18) { printf("Adul tn"); } else { printf("Mino rn"); }
  • 38.
    `else-if` Statements Chaining Multiple Conditions Allowsyou to test multiple conditions in sequence; `if (condition1) { / code / } else if (condition2) { / code / } else { / code / }` 01 Examples 02
  • 39.
    `else-if` Statements Examples int score= 85; if (score >= 90) { printf("A n"); } else if (score >= 80) { printf("B n"); } else if (score >= 70) { printf("C n"); } else { printf("Fail n"); }
  • 40.
    `switch` Statement Syntax Using `switch`for Multiple Cases Allows you to select one of several code blocks based on the value of an expression.
  • 41.
    `switch` Statement Syntax switch (expression){ case value1: /* code */ break; case value2: /* code */ break; default: /* code */ }
  • 42.
    `switch` Statement Examples int day= 3; switch (day) { case 1: printf("Monday n"); break; case 2: printf("Tuesday n"); break; case 3: printf("Wednesdayn"); break; default: printf("Other dayn"); }
  • 43.
  • 44.
    `while` Loop Executes ablock of code repeatedly as long as a condition is true; `while (condition) { / code / }` Basic `while` Loop Examples
  • 45.
    `while` Loop Examples int i= 0; while (i < 5) { printf("%d n", i); i++; }
  • 46.
    `for` Loop Provides amore structured way to write loops with initialization, condition, and increment/decrement in one line; `for (initialization; condition; increment/decrement) { / code / }` Basic `for` Loop Examples
  • 47.
    `for` Loop Examples for (inti = 0; i < 5; i++) { printf("%d n", i); }
  • 48.
    Similar to `while`loop, but the code block is executed at least once because the condition is checked at the end; `do { / code / } while (condition);` Basic `do-while` Loop Examples `do-while` Loop
  • 49.
    `do-while` Loop Examples int i= 0; do { printf("%d n", i); i++; } while (i < 5);
  • 50.
    `break` Statement Terminates theloop or `switch` statement immediately. `continue` Statement Skips the rest of the current iteration and continues with the next iteration. `goto` Statement Transfers control to a labeled statement; Use with caution. Examples `break`, `continue`, and `goto`
  • 51.
    `break`, `continue`, and`goto` Examples for (int i = 0; i < 10; i++) { if (i == 5) break; // Exit loop if (i % 2 == 0) continue; // Skip even numbers printf("%dn", i); }
  • 52.
  • 53.
    Importance of CProgramming Highlight the significance of C in various fields. Recap Briefly review the main topics covered (variables, operators, control flow, loops). Summary of Key Concepts
  • 54.
    Next Steps Recommend books,online courses, and websites for further study. Further Learning Resources Encourage students to practice coding to reinforce their understanding. Practice Exercises
  • 55.
    Q & A Addressquestions and clarify any doubts about the topics covered. Open the floor to Questions
  • 56.