Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

PROBLEM

SOLVING
THROUGH
C

NAME: D . Yeshwanth Kumar

ROLL NO: 22B81A0564


TOPICS TO BE DISCUSSED
➢ Data type
➢ Operators
➢ Decision making statements
➢ Looping statements
➢ Functions
DATA TYPES
Data type is used for representing the data in main memory
(RAM) of the computer. Data types represent the different
values to be stored in the variable. Every data type has a
range of values. The compiler allocates memory space for
each variable or constant according to its data type
C has the following data types:
➢ Int
➢ Char
➢ Float
➢ double
INTEGER DATA TYPE
➢ The integer data type in C is used to store the whole
numbers without decimal values.
➢ “int” keyword is used to refer integer data type.
➢ Any decimal number declared with int data type will
be converted to integer values and will be stored.
➢ Signed int cannot store negative values but unsigned
int can store negative values.
▪ Size: 2 bytes or 4 bytes
▪ Format Specifier: %d
CHARECTER DATA TYPE.
➢ Character data type allows its variable to store
only a single character.
➢ The storage size of the character is 1.
➢ It is the most basic data type in C.
▪ Size: 4 bytes
▪ Format Specifier: %f
FLOATING-DATA TYPE
Floating-point data type consists of two data types.
➢ Float
➢ Double
FLOAT DATA TYPE
➢ Float in C is used to store decimal and exponential
values.
➢ It is used to store decimal numbers (numbers with
floating point values) with single precision.
▪ Size: 4 bytes
▪ Format Specifier: %f
DOUBLE DATA TYPE
➢ A Double data type in C is used to store decimal
numbers with double precision.
➢ It is used to define numeric values which hold
numbers with decimal values in C.
➢ It can easily accommodate about 16 to 17 digits
after or before a decimal point.
▪ Size: 8 bytes
▪ Format Specifier: %lf
OPERATORS

Operators are used to perform operations on variables


and values.
C divides the operators into the following groups:
➢ Arithmetic operators
➢ Assignment operators
➢ Relational operators
➢ Logical operators
➢ Bitwise operators
Arithmetic operators
• Arithmetic operators are used to perform common
mathematical operations.
+,-,*,/,%,++,-- are arithmetical operators.

Assignment operators
• Assignment operators are used to assign values to
variables.
+=,-=,*=,/=,%=,&=,^=,|=,~=,<<=,>>= are
assignment operators.
Relational operators
>,<,<=,>=,==,!= are relational operators

Logical operators
&&,||,! are the logical operators

Bitwise operators
& ,| ,^ , ~ , >> , << are bitwise operators.
CONDITIONAL STATEMENTS
➢ C conditional statements allow you to make a
decision based upon the result of a condition.
➢ These statements are called Decision Making
Statements or Conditional Statements.
➢ So far, we have seen that all sets of statements in the
C program execute sequentially in the same order in
which they are written and appeared.
➢ This occurs when there are no jump-based
statements or repetitions of specific calculations.
Conditional statements in c are :

❖ If statement
• if statement
• if-else statement
• Nested if-else statement
• else if-statement
❖ goto statement
❖ switch statement
❖ Conditional Operator
LOOPING STATEMENTS
➢ Loop is used to execute the block of code several
times according to the condition given in the loop.
➢ It means it executes the same code multiple times so
it saves code and also helps to traverse the elements
of an array.
There are 3 types of loop –
•while loop
•do – while loop
•for loop
1.while Loop –
While loop execute the code until condition is
false.

SYNTAX-

while(condition)
{
//code
}
2. do – while loop
It also executes the code until condition is false. In this at
least once, code is executed whether condition is true or
false but this is not the case with while. While loop is
executed only when the condition is true.
Syntax
do
{
//code
}
while(condition);
3. for Loop-
It also executes the code until condition is false. In this
three parameters are given that is
•Initialization
•Condition
•Increment/Decrement
Syntax
for (initialization;condition;increment/decrement)
{
//code
}
FUNCTIONS

➢ A function is a block of code which only runs when it is


called.
➢ You can pass data, known as parameters, into a
function.
➢ Functions are used to perform certain actions, and
they are important for reusing code: Define the code
once, and use it many times.
TYPES OF functions
Type of Functions May be classified based on arguments
and return value into following categories
1. Function with no arguments and no return value
2. Function with no arguments and return value
3. Function with arguments and no return value
4. Function with arguments and return value
THANK YOU

You might also like