0% found this document useful (0 votes)
3 views

Programming Practice Week3

The document outlines the objectives and content of a programming practice course focused on fundamental programming concepts, including variables, data types, control structures, and loops. It provides examples of variable declarations, input/output methods, and conditional statements, along with practice exercises for calculating averages and checking prime numbers. The course aims to prepare students for more advanced topics in programming, such as functions and modular programming.

Uploaded by

joekingehigie
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Programming Practice Week3

The document outlines the objectives and content of a programming practice course focused on fundamental programming concepts, including variables, data types, control structures, and loops. It provides examples of variable declarations, input/output methods, and conditional statements, along with practice exercises for calculating averages and checking prime numbers. The course aims to prepare students for more advanced topics in programming, such as functions and modular programming.

Uploaded by

joekingehigie
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Programming Practice Course

Week 3: Fundamentals of
Programming
Presented by: Isaac Muckson Sesay
Week Objectives
• - Understand basic programming concepts.
• - Learn to work with variables and data types.
• - Explore control structures like loops and
conditionals.
• - Develop simple programs using these
fundamentals.
Introduction to Variables
• - Variables store data values.
• - Examples:
• - `int age = 25;` (integer)
• - `float height = 5.9;` (decimal)
• - `char grade = 'A';` (character)
• - `string name = "John";` (text)
• - Choose meaningful variable names.
Data Types
• - Basic data types:
• - Integer (`int`)
• - Floating-point (`float`, `double`)
• - Character (`char`)
• - Boolean (`true`/`false`)
• - Composite types:
• - Arrays
• - Strings
• - Understand type compatibility and conversions.
Input and Output
• - Input:
• - `scanf()` or similar methods to read user
input.
• - Example: `scanf("%d", &age);`
• - Output:
• - `printf()` or similar methods to display
output.
• - Example: `printf("Age: %d", age);`
Conditional Statements
• - Use conditionals to control program flow.
• - Examples:
• - `if (age > 18) { printf("Adult"); }`
• - `else { printf("Minor"); }`
• - `if-else if-else` for multiple conditions.
• - Nested conditionals and logical operators.
Loops in Programming
• - Loops repeat a block of code:
• - `for` loop: Used for a known number of
iterations.
• Example: `for (int i = 0; i < 10; i++) {}`
• - `while` loop: Repeats while a condition is true.
• Example: `while (x > 0) {}`
• - `do-while` loop: Ensures the block runs at least
once.
• - Avoid infinite loops.
Example Program: Sum of Numbers
• ```c
• int sum = 0;
• for (int i = 1; i <= 10; i++) {
• sum += i;
• }
• printf("Sum: %d", sum);
• ```
Debugging Basics
• - Common errors:
• - Syntax errors: Missing `;`, mismatched `{}`.
• - Runtime errors: Dividing by zero, invalid
input.
• - Logic errors: Incorrect calculations.
• - Use debugging tools or print statements to
find issues.
Practice Exercise 1
• - Problem: Write a program to calculate the
average of 5 numbers.
• - Steps:
• 1. Declare variables.
• 2. Use a loop to get user inputs.
• 3. Calculate and display the average.
Practice Exercise 2
• - Problem: Check if a given number is prime.
• - Steps:
• 1. Input a number.
• 2. Use a loop to check divisibility.
• 3. Output whether the number is prime.
Wrap-Up and Q&A
• - Summary of programming fundamentals.
• - Questions or challenges faced?
• - Prepare for Week 4: Functions and Modular
Programming.

You might also like