Introduction to C Programming Language
Introduction to C Programming Language
Introduction
A computer program is a set of instructions used to operate a computer to produce a specific result.
Writing computer programs is called computer programming. The languages used to create computer
programs are called programming languages.
Programming IDE
IDE stands for Integrated Development Environment. It's essentially an environment for editing a program. An example
of an online IDE is http://cpp.sh/.
Page 1
Created by Turbolearn AI
printf("Hello World");
A Simple Program
Here is an image showing a C++ "Hello World" program in a C++ shell. Note the #include <iostream> which is a directive,
not an instruction.
Branch Statement
A branch statement allows us to select an action based on some conditions.
For example: If a user inputs a valid account number and PIN, then allow money withdrawal; otherwise, alert a
message.
An if statement works like "If condition is met, then execute the task".
Page 2
Created by Turbolearn AI
Simple IF
if(boolean_expression) {
// body of if
}
The boolean_expression returns true or false. A value of zero is false, while other values are true.
If Else Statement
Page 3
Created by Turbolearn AI
Multiple Conditions
Conditions are checked one by one. When one condition is true, the if is stopped.
Nested IF
Page 4
Created by Turbolearn AI
Switch case
Page 5
Created by Turbolearn AI
The expression inside switch must evaluate to an integer, character, or enumeration constant. The switch...case structure
only works with integral, character, or enumeration constants. The execution jumps directly to the right condition instead
of checking one by one as in an if else statement.
Used when there are conditions instead of a Used when there is a list of choices from which you need
Conditions
list of choices. to take a decision.
Number of Choices are in the form of an integer, character, or
Suited for a few number of conditions.
Checks enumeration constant.
Further Enumerable declaration, state machine, deterministic
N/A
Reading finite automata
Looping Statements
Page 6
Created by Turbolearn AI
Page 7
Created by Turbolearn AI
Nested Loop
Page 8
Created by Turbolearn AI
Question: Why do we need a break statement instead of putting it in the condition statement of the loop?
Continue in Loop
Example
Page 9
Created by Turbolearn AI
Array in C/C++
Page 10
Created by Turbolearn AI
DATA_TYPE array_name[SIZE];
Example:
int marks[5];
Page 11
Created by Turbolearn AI
Introduction to Function
A function is a collection of statements grouped together to do some specific tasks. printf(), scanf(), and main() are
examples of functions.
Advantages of Functions
Reusability of code: Functions once defined can be used several times.
Modular design of code: Modular programming leads to better code readability, maintenance, and reusability.
It is easier to write programs using functions. You can write code for separate tasks individually in a separate
function.
Code maintenance and debugging are easier: In case of errors in a function, you only need to debug that particular
function instead of debugging the entire program.
Function Declaration
return_type function_name(parameter_list);
Page 12
Created by Turbolearn AI
void main(){
int n1 = 1, n2 = 2;
swap(&n1, &n2);
return;
}
Introduction
Python is a popular programming language created by Guido van Rossum and released in 1991.
Page 13
Created by Turbolearn AI
Python Indentation
if 5 > 2:
print("Five is greater than two!")
If Statement
FOR Loop
a = [1, 2, 3, 4, 5]
N = len(a)
for i in range (0, N):
print(a[i])
Arrays in Python
a = [1, 2, 3, 4, 5]
print(a[0])
WHILE Loop
Function
c = 4
print(sum_numbers(c, 3))
Page 14
Created by Turbolearn AI
The Adafruit IO Feeds page allows you to set up the backend for your IoT project. In the image, you can see options for
creating new feeds and groups. A table lists existing feeds with their names, keys, and last values.
In lowercase.
Without special characters.
Page 15
Created by Turbolearn AI
The Adafruit IO dashboard displays real-time information and controls. In the image, you can see visualizations for
temperature, humidity, electrical conductivity, and controls for systems like lights and pumps.
Page 16
Created by Turbolearn AI
import sys
from Adafruit_IO import MQTTClient
import random
import time
while True:
time.sleep(10)
print("Your Code Here")
value1 = random.randint(20, 80)
client.publish("sensor1", value1)
Page 17