Name: Mahtab Alam Ansari: Supreme Institute of Management and Technology
Name: Mahtab Alam Ansari: Supreme Institute of Management and Technology
Technology
Name : Mahtab Alam
Ansari
Stream :
BCA
Semester :
01
Year :
01
Subject name : Programming for problem
solving through C
Subject code :-
BCAC102
PPT topic :- C
programming
CHAPTER- CHAPTER- CHAPTER-
01 of
“Overview 02
“Constants,Varaibl
es & Data Types”
03
“Operators
an
C”
Expressions
”
CHAPTER-
07
“Arrays
”
CHAPTER-
01
“Overview of
C”
Overvie
• Introduction w
• History of C
• Importance of C
• Sample C programs
• Basic structures of C programs
• Programming style
• Executing a C program
INTRODUCTIO
N
C programming language is known for its simplicity and efficiency. It is
the best choice to start with programming as it gives you a foundational
understanding of programming.
History of
C
• Created in 1972: Developed by Dennis Ritchie at
Bell Labs to improve upon the B language for
system programming.
Dennis
• Foundation for Other Languages: C influenced and Ritchie
became the basis for languages like C++, Java,
and many others.
Importance
of CC is the base for many modern
• Foundation for Other Languages:
languages like C++, Java, and Python.
Basic Addition
Program: #include<stdio.h>
int main() {
int a = 5, b = 3;
printf("Sum: %d", a
+ b);
return 0;
}
Basic Structures of C
Programs
• Preprocessor Directives :
#include<stdio.h>
• Main Function : int
main() { }
• Variable Declaration : int
a, b;
• Logic : Statements to perform
operations.
• Return Statement : return 0; to indicate program
completion.
Programming Style
Indentation and in
ProperC
indentation improves
Readability : readability.
Example int main() {
: int num =
10;
printf("%d",
num);
}
Meaningful Variable Names: Use descriptive names (e.g., totalMarks
instead of t).
Consistent Bracing Style: Keep braces {} aligned for
better clarity.
Executing a C
Steps to Program
Execute :
1. Write the Code: Write .c file in a text
editor.
2. Compile: Use a compiler like GCC (gcc
program.c).
3. Link: The linker resolves references
between files.
4. Execute: Run the compiled program
(./a.out).
Example int
: age;
Constant
Definition: Fixed values that do s
not change during
execution.
Types
:
• Integer Constants : Whole numbers (e.g.,
100, -45).
• Floating-Point Constants : Decimal numbers (e.g.,
3.14, -0.01).
• Character Constants : ingle characters enclosed in single quotes
(e.g., 'A', '5').
• Syntax variable_name =
: value;
Example
: int num = 10;
char letter =
'B';
Defining Symbolic
• Definition : AConstants
name that represents a
constant value
• Syntax #define CONSTANT_NAME
: value
• Characteristic
s: • Cannot be
modified.
• Typically written in uppercase
letters.
Example #define PI
: 3.14159
CHAPTER-
03
“Operators and
Expressions”
Overvie
• Introduction
w • Arithmetic expressions
• Arithmetic of Operators • Bitwise operators
• Relational operators • Evaluation of expressions
• Logical operators • Precedence of arithmetic
• Assignment operators operators
• Increment and decrement • Operator precedence and
operators associativity
• Conditional operator
INTRODUCTIO
N
An operator is a symbol that tells the compiler to perform specific
mathematical, logical, or relational operations.
Arithmetic
Operators
Definition: These operators perform basic mathematical
operations like addition, subtraction, multiplication, etc.
List of
Operators:
Addition Subtraction Multiplication Division Modulus
[+] [-] [*] [/] [%]
#include #include #include #include #include
<stdio.h> <stdio.h> <stdio.h> <stdio.h> <stdio.h>
void main() void main() void main() void main() void main()
{ { { { {
int int
int int int
a=5,b=10,sub; a=5,b=10,mul;
a=2,b=3,sum; a=5,b=10,div; a=5,b=10,mod;
sub = a - b; mul = a * b;
sum = a + b; div = a / b; mod = a % b;
printf("The printf("The
printf("The sum printf("The printf("The
substraction of multiplication of
of %d and %d is division of %d modulus of %d
%d and %d is %d and %d is %d\
%d\n", a, b, and %d is %d\n", and %d is %d\n",
%d\n", a, b, sub); n", a, b, mul);
a, b, div); a, b, mod);
sum);
Relational
Operators
Definition: These operators compare two values and return
true or false.
List of
Operators:
Logical
Operators
Definition: These operators are used to combine multiple
conditions.
List of
Operators:
Assignment
Operators
Definition: These operators
variables.
assign values to
Increment and
Decrement Operators
Definition: These operators increase or decrease the value of a
variable by 1.
Increment operator Decrement operator
in C in C
Conditional
Operators
Definition: A shorthand for if-else statements, also known as the
ternary operator.
Arithmetic Operators
In C
Bitwise
Operators
Definition: These operators perform bit-level operations on
integers.
Evaluation of
Expressions
Definition: The process by which an expression is simplified or
calculated.
3 + 5 * 2 is evaluated as 3 +
(5 * 2).
Operator Precedence and
Associativity
Definition: If two operators have the same precedence, associativity defines
the direction in which the expression is evaluated.
Example: 3 - 2 + 5 is
evaluated from left to right
because - and + are left-
associative
CHAPTER-
04
“Managing Input and Output
Operators”
Overvie
w
• Introduction
• Reading a Character
• Writing a Character
• Formatted input
• Formatted output
INTRODUCTIO
N
In C programming, input refers to taking data from the user or a file,
and output refers to displaying data to the screen or another device.
Example
: char ch;
ch = getchar(); // Reads a character from
the user
Example
: int num;
scanf("%d", &num); // Reads an integer
value
Example
: int num = 5;
printf("The number is: %d", num); //
Outputs: The number is: 5
Synta Exampl
x: e:
if (condition) {
if (age > 18) {
// code to be executed if
printf("You are an adult.");
condition is true
}
}
Simple IF
Statement
Definition: A simple if statement checks a single
condition.
Synta Exampl
x: e:
Synta Exampl
x: e:
Synta Exampl
x: e:
if (condition1) { if (x > 0) {
if (condition2) { if (x < 100) {
// code if both printf("x is between 1
condition1 and condition2 and 99");
are true }
} }
}
The ELSE IF
Ladder
Definition: Multiple conditions are checked using ELSE IF, where
the first true condition's block is executed.
Synta Exampl
x: e:
if (condition1) { if (score > 90) {
// code if condition1 is true printf("Grade A");
} else if (condition2) { } else if (score > 75) {
// code if condition2 is true printf("Grade B");
} else { } else {
// code if all conditions are printf("Grade C");
false }
}
The Switch
Statement
Definition: The switch statement allows selecting one of many blocks
of code to execute.
Synta Exampl
x: e:
switch (expression) {
switch (day) {
case constant1:
case 1:
// code for case 1
printf("Monday");
break;
break;
case constant2:
case 2:
// code for case 2
printf("Tuesday");
break;
break;
default:
default:
// code if none of the
printf("Invalid day");
cases match
}
}
The ?:
Operator
Definition: Also known as the conditional or ternary operator, it’s a
shorthand for the IF ELSE statement.
Synta Exampl
x: e:
Synta Exampl
x: e:
if (x < 0) {
goto label;
goto error;
...
}
label:
error:
// code to be
printf("Error:
executed
Negative
number");
CHAPTER-
06
“Decision-Making and
Looping”
Overview
• Introduction
• The WHILE statement
• The DO statement
• The FOR statement
• Jumps in LOOPS
INTRODUCTIO
N
Looping structures allow repeating a set of instructions until a
condition is met.
Synta Exampl
x: e:
int i = 0;
do {
do {
// code to
be executed
printf("%d",
} while
i);
(condition);
i++;
} while (i <
5);
The FOR
Statement
Definition: The FOR loop repeats a block of code a specific
number of times.
Synta Exampl
x: e:
printf("%d",
i);
CHAPTER-
07
“Arrays
”
Overview
• Introduction
• One-dimensional arrays
• Two-dimensional arrays
• Initializing two-dimensional
arrays
• Multidimensional arrays
INTRODUCTIO
N
An array is a collection of variables that are stored in contiguous
memory locations. All elements in an array must be of the same data
type.
Arra
y
Synta Exampl
x: e:
int numbers[5]; // Declares
dataType
an array of 5 integers
arrayName[arraySize];
Synta Exampl
x: e:
data_type int
array_name[array_size]; numbers[5];
Synta Exampl
x: e:
Synta Exampl
x: e:
dataType arrayName[rows]
[columns] = {{value1, value2}, int matrix[2][2] = {{1, 2},
{value3, value4}}; {3, 4}};