0% found this document useful (0 votes)
99 views185 pages

Module 1

The document outlines the course objectives, syllabus, evaluation, and first module content for CSEN1011 Problem Solving and Programming with C taught by Dr. D.V.N. Siva Kumar at GITAM University. The course introduces students to problem solving techniques like top-down design and algorithms, and teaches the fundamentals of C programming including data types, operators, control structures, functions, arrays, and pointers. Students will be evaluated based on quizzes, assignments, exams, and attendance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views185 pages

Module 1

The document outlines the course objectives, syllabus, evaluation, and first module content for CSEN1011 Problem Solving and Programming with C taught by Dr. D.V.N. Siva Kumar at GITAM University. The course introduces students to problem solving techniques like top-down design and algorithms, and teaches the fundamentals of C programming including data types, operators, control structures, functions, arrays, and pointers. Students will be evaluated based on quizzes, assignments, exams, and attendance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 185

CSEN1011

Problem Solving and


Programming with C
Dr. D.V.N. Siva Kumar
Assistant Professor
CSE Department
GITAM University, Hyderabad Campus
Email: vdonthu@gitam.edu
Agenda
• Course Objectives
• Syllabus
• Evaluation
• Attendance Requirements
• Module 1 Content

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Course Objectives
1. Familiarize the student with the steps involved in writing and running a
compiled program.
2. Enable the student to build program logic with algorithms and
flowcharts.
3. To enable the students to understand the features and constructs of C
programming such as Data Types, Expressions, Loops, Functions, Arrays,
Pointers and Files
4. Demonstrate the handling of variables and input-output operations in C
5. Train the student to convert the problem logic into C language code
using a Top-Down Approach

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Modules of the Syllabus
Module 1: Introduction to Computer Problem Solving (Top-Down
Design, Algorithm, and Flowchart)
Structure of C Program, Keywords, Identifiers, Data Types, Variable
Declaration, Constants, Input/Output Functions, Operators,
Expressions, Precedence and Associativity, Expression evaluation, and
Type Conversions.
Module 2: Control Structures
Selection Statements, Repetitive Statements (Loops), Unconditional
statements and Pointers

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Modules of the Syllabus (Cont…)
Module 3: Functions
Types of functions, User-Defined Functions, Parameter Passing by Value and
Pointer (Address of other variables), Recursive Functions.
Dynamic Memory Allocation Functions, Pointer to Functions, and Storage
Classes.

Module 4: Arrays and Strings


Array declaration and initialization, Search: Linear search, Binary search,
Sorting: Bubble sort, Two Dimensional Arrays, Multi-Dimensional Arrays,
Arrays and Pointers, Strings, String Manipulation functions, Unformatted IO
functions, Strings and Pointers

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Modules of the Syllabus (Cont…)
Module 6: Structures and Files
Structures: Declaration, Initialization, Accessing members of a
structure, Operations on structures, Structures with Arrays and
Pointers, Nested Structures, Structures and Functions, Structures and
Pointers, Unions.
Files: Creation, Opening, and Closing Files, File Input/Output functions.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Course Evaluation Components
1. Quizzes (25%): Totally 5 quizzes (One Quiz for each module). Each quiz
carries 5 Marks.
2. Coursera Course (5%): One course to be completed on Coursera. It
carries 5 Marks. You will be required to submit the course completion
certificate on Moodle.
The course name is: C for Everyone
1. Mid-Semester Exams (30%): 3 mid exams and each carries 10 marks.
2. Project or Programming Assignments (10%): It will be evaluated for 10
Marks.
3. End-Semester Exam (30%)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Expected Attendance
• 75% attendance is mandatory to appear for any exam.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Academic Honesty and Integrity
Each student is expected to maintain academic honesty and integrity
throughout the course.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method
1.Specify the problem requirements.
2.Analyse the problem.
3.Design the algorithm to solve the problem.
4.Implement the algorithm.
5.Test and verify the completed program.
6.Maintain and update the program.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method (Cont…)
1. Problem:
• Specifying the problem requirements forces us to state the problem
clearly and unambiguously and to gain a clear understanding of what
is required for its solution.
• Our objective is to eliminate unimportant aspects and zero in on the
root problem so that we can obtain the clear idea of a problem.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method (Cont…)
2. Analysis:
• Analyzing the problem involves identifying the problem:
(a) Inputs: the data we have to work with;
(b) Outputs: , that is, the desired results; and
(c) Any additional requirements or constraints on the solution.

At this stage, you should also determine


• The required format in which the results should be displayed (for example, as
a table with specific column headings) and develop a list of problem variables
and their relationships. These relationships may be expressed as formulas.
Note: The goal is to determine to determine the inputs and outputs

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


2. Analysis (Cont…)
Example Problem: Compute and display the total cost of apples given the number of pounds of apples
purchased and the cost per pound of apples

Problem Inputs
Quantity of apples purchased (in pounds)
Cost per pound of apples (in dollars per pound)

Problem Output
Total cost of apples (in dollars)

Once you know the problem inputs and outputs, develop a list of formulas that specify relationships
between them.
The general formula is :
Total cost = Unit cost* Number of units
The above computes the total cost of any item purchased. Substituting the variables for our
particular problem yields the formula
Total cost of apples = Cost per pound * Pounds of apples
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Problem Abstraction
Def(Abstract): This process of modeling a problem by extracting the
essential variables and their relationships is called abstraction

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method (Cont…)
3. Design
• Designing the algorithm to solve the problem requires us to develop a list of
steps called an algorithm to solve the problem and to then verify that the
algorithm solves the problem as intended.

Def(Algorithm): Algorithm is a list of steps that solve a given problem.

Top-down Design:
• It is the design process that involves breaking a problem into its major
subproblems and then solving the subproblems
• In top-down design (also called divide and conquer ), we first list the major steps
or subproblems, that need to be solved. Then we solve the original problem by
solving each of its subproblems.
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
3. Design (Cont…)
Algorithm for solving any programmable problem involves:
1. Get the data.
2. Perform the computations.
3. Display the results.

Note: The perform-the-computations step may need to be broken


down into a more detailed list of steps through a process called
stepwise refinement .

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Desk Checking Algorithm (Human check)
• Desk checking is an important part of algorithm design that is often
overlooked.
• To desk check an algorithm: we must carefully perform each
algorithm step (or its refinements) just as a computer would and
verify that the algorithm works as intended.
• This helps us save time and effort if we locate algorithm errors early
in the problem-solving process.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method (Cont…)
4. Implementation:
- Implementing the algorithm involves writing it as a program.
- We must convert each algorithm step into one or more statements in a
programming language.

5. Testing:
• Testing and verifying the program requires testing the completed program to verify that
it works as desired.
• Here, don’t rely on just one test case.
• Run the program several times using different sets of data to make sure that it works
correctly for every situation provided for in the algorithm.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Software Development Method (Cont…)
6. Maintenance:
Maintaining and updating the program involves modifying a program
to remove previously undetected errors and to keep it up-to-date as
government regulations or company policies change.

Note: We use the first five steps of the software development method to solve any
programming problems

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example: Develop an algorithm for the
problem of converting miles to kilometers.
1. Problem:
Our summer surveying job requires us to study some maps that give
distances in kilometers and some that use miles. You and your coworkers
prefer to deal in metric measurements. Write a program that performs the
necessary conversion.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example: Develop an algorithm for the problem of
converting miles to kilometres (Cont…)
2. Analysis (Determination of Inputs and Outputs):
• The first step in solving this problem is to determine what we are asked to do.
• We must convert from one system of measurement to another, but are we
supposed to convert from kilometers to miles, or vice versa?
• The problem states that we prefer to deal in metric measurements, so we must
convert distance measurements in miles to kilometers.
• Therefore, the problem input is distance in miles and the problem output is
distance in kilometers .
Note: To write the program, we need to know the relationship between miles and
kilometers. We know that one mile equals 1.609 kilometres.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


2. Analysis (Cont…)
DATA REQUIREMENTS
• Problem Input
- miles /* the distance in miles*/
• Problem Output
- kms /* the distance in kilometers */
Relevant Formula
1 mile = 1.609 kilometres

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example: Develop an algorithm for the problem of
converting miles to kilometres (Cont…)
3. Design:
• Formulate the algorithm that solves the problem.
• Begin by listing the three major steps, or subproblems, of the
algorithm.

ALGORITHM
1. Get the distance in miles.
2. Convert the distance to kilometers.
3. Display the distance in kilometers.

Note: Step 2 is fairly straightforward, but some detail might help:


DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Step 2 Refinement

2.1 The distance in kilometers is 1.609 times the distance in miles.

The refinement of step 2 is numbered as step 2.1 and is indented under step 2.

ALGORITHM WITH REFINEMENTS


1. Get the distance in miles.
2. Convert the distance to kilometers.
2.1 The distance in kilometers is 1.609 times the distance in miles.
kilometers=1.609*miles
3. Display the distance in kilometers.

Desk check:
• Let’s desk check the algorithm before going further.
- If step 1 gets a distance of 10.0 miles
- step 2.1 would convert it to 1.609 *10.00 = 16.09 kilometers.
- This correct result would be displayed by step 3.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example: Develop an algorithm for the problem of
converting miles to kilometres (Cont…)

4: Implementation:
To implement the solution, we must write the algorithm as a C program.
• To do this, you must first tell the C compiler about the problem data
requirements—that is, what variables we are using for input and what variables
for output
• Next, convert each algorithm step (including refinement steps) into one or more
C programming statements.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


4. Implementation (Cont…)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example: Develop an algorithm for the problem of
converting miles to kilometres (Cont…)
5. Testing (or Program Testing or Whitebox
testing):

Input

Output

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solving a Problem
• To develop a program, a programmer must complete the
following steps:
a. Understand the problem.
b. Develop a solution using either Algorithm or Flowchart.
c. Write the program .
d. Test the program.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Flowchart
• A flowchart is a diagram that depicts a process, system or
computer algorithm.
• It gives a pictorial representation of an algorithm
• It can also be defined as program design tool in which standard graphical
symbols are used to represent the logical flow of program data for solving
the given problem.
• It reflects the logical flow of a program, i.e., it represents sequence of steps
to be followed for solving a given problem.
• Flowcharts are widely used in multiple fields to document, study,
plan, improve and communicate often complex processes in clear,
easy-to-understand diagrams.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Auxiliary Symbols used in Flowchart

• A flowchart is a combination of symbols. Some symbols enhance the readability


or functionality of the flowchart; they do not directly show instructions or
commands.
• They show the start and stop points, the order and sequence of actions, and how
one part of a flowchart is connected to another.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Start and Stop Symbols
• An oval shows the beginning or ending of an algorithm.
• Oval symbol is used to show the beginning of an algorithm, we write the
word START inside the oval. It is also used to show the ending of an
algorithm.
• We write the word STOP or RETURN in the oval symbol.
This is an example of a flowchart of a
program that does nothing.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Flowlines
• Flow lines show the order or sequence of actions in a program.
• They connect symbols. Usually a symbol has some entering and some
exiting lines.
• The Start oval has only one exiting line. The STOP oval has only one
entering line.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Primary Symbols
• Programmers use the primary symbols to show the instructions or
actions needed to solve the problem presented in the algorithm.
• With these symbols, it is possible to represent all three structured
programming constructs: sequence, decision, and repetetion.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sequence
• Sequence statements simply represent a series of actions that must
continue in a linear order.
• Sequence symbols do not allow any decisions or flow changes within
the symbol.
• Flowcharts use four sequence symbols for the given statements. They
are provided below.
-Assignment
- Input/Output
- Module call
- Compound statement.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sequence Symbols (Cont…)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Assignment Statement
• The assignment statement is shown using a rectangle symbol.
• Within the assignment symbol, the assignment operator is shown as
a left-pointing arrow.
• At the right side of the arrow, there is an expression whose value
must be stored in the variable at the left side.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Input/Output Statement
• A parallelogram shows any input or or writing on the output, such as reading from a keyboard or
writing on system console.

Flowchart for an
algorithm that reads the
value of two variables
from the keyboard and
then in reverse order

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Module Call Statement
• The symbol used for a module call is a rectangle with two vertical bars inside.
• The flowchart for the called module must be somewhere else.
the module
Flowchart for AVRG(rslt, x, y, z)
finding the average
of three numbers.

Module call
statement (AVRG(ave,
a,b,c)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Null Statement
• It is worth noting that do nothing is a valid statement. It is commonly
referred to as a null statement. The null statement is considered as a
sequence statement since it cannot changes the flow direction of a
program. There is no symbol for a null statement.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Connectors
We use a circle symbol with a number in it to show connectivity.
It is used in two situations.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Representation of Condition in a Flowchart:
Two-way Selection
• Rhombus symbol can be used to represent a condition in flowchart.
• The outcome of condition has two values: 1. True (T) represents on
the right side of Rhombus symbol and 2. False (F) represents the left
side of Rhombus symbol.

Note: The above one is condition with two possible outcomes. This is called Two-way
DVNselection.
Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Multi-way Selection

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compound statement
• In a C program, compound statements represent a block of code, i.e., code that is enclosed in
braces.
• We use a dashed rectangle in flowchart to represent a compound statement.

Checking Compound statement that


outcome of a Reads a number and subtract 10
Condition

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Flowchart example with Multi-way selection
The below one is a Flowchart for calculating Grade Point
Average (GPA)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Concept of Loop in Flowchart
• Loop represents a set of statements that will be executed again and again.
• In flowchart, the below can be used to represent a loop of a program.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Condition

Note: Loops are useful when we want to execute a set of statements repeatedly until some
condition becomes true.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


How do you create Flowchart diagrams?.
• Using tools like Raptor or drawio
• Raptor tool can be downloaded from
https://raptor.martincarlisle.com/

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


What is C?
• It is a programming language developed at AT&T’s Bell Laboratories
of USA in 1972 by Dennis Ritchie.
• C became popular because it is simple and easy to use.

“C has been already superseded by languages like C++, C# and Java,


so why bother to learn C today”:
- It helps in acquiring basic programming skills so that it enables
everyone to understand any programming language. So it makes more
sense to learn C first and then migrate to any other programming
language such as C++, C#, or Java.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


What is C? (Cont…)
- Major portions of Operating Systems like Windows, Unix, Linux and
Android are written in C. If one extends the OS to work with new devices,
one needs to write device driver programs. These programs are written
exclusively in C.
- Consumer devices like Microwave ovens, Washing machines, and digital
cameras are getting smarter with each passing day. This smartness comes
from a microprocessor, an operating system and a program embedded in
these devices. These programs have to run fast and work in limited amount
of memory. C is language of choice while building such OSs and programs.
- Gaming Frameworks like (DirectX) are used for creating user games. These
games are written in C.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Basic Structure of a C program
A C program is divided into different sections that are provided below:

Documentation Section
Link Section
Definition Section
Global Declaration Section
main() //Main Function Section
{
Declaration part
Executable part
}
Subprogram Section
Function 1
Function 2
(User defined functions)
-
-
Function n DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Basic Structure of a C program (Cont…)
Section Description

1. Documentation Section Consists of the description of the program, programmer's name, and creation date.
These are generally written in the form of comments.
Comments are two types:
- Single line comment, e.g., // comment text
- Multiline comment: /*
Line 1 text
Line 2 text
Line 3 text
/*
2. Link Section All header files are included in this section which contains different functions from the
libraries. It provides instructions to the compiler to link functions from the system
library. A copy of these header files is inserted into your code before compilation.
3. Definition Section Includes preprocessor directives, which contains symbolic constants.
E.g.: #define allows us to use constants in our code. It replaces all the constants with its
value in the code. Example: #define PI 3.14
4. Global Declarations Section It includes declaration of global variables, function declarations (to be used subprogram
section, static global variables, and user-defined functions.
- Global variables declared can be used (more than one function), i.e., throughout the
program. DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Basic Structure of a C program (Cont…)
Section Description
5. main() function section For every C program, the execution starts from the main() function. It is mandatory to
include a main() function in every C program.

6. Subprogram section Includes all user-defined functions (functions the user provides). They can contain the
inbuilt functions, and the function definitions declared in the Global Declaration
section. These are called in the main() function.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Executing a C program
Executing a program written in C involves the following the steps:
• Creating the program using Notepad or gedit and save it with .c
extension.
• Compiling the program
• Linking the program with functions that are needed from the C
library or user defined functions. (This step is optional)
• Executing the program

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


First C program: To display a message “Hello
World”
#include<stdio.h>
int main()
{
printf("Hello World");
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution of a C Program
There are two procedures to compile and execute a C program
Procedure 1 (Default): Procedure 2:
1. Compile the program Hello.c on GCC as follows 1. Compile the program Hello.c on GCC as follows
gcc Hello.c gcc Hello.c -o Hello
// The above line creates a.out file after successful // the above line create a Hello file (this is executable file).
compilation. a.out is called as the executable file. 2. Execute the Hello file
2. Execute the file a.out as shown below: ./Hello
./a.out

Output

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


How to know the return value of a C program
on Ubuntu system with GCC.
The command is provided below for use on Ubntu System.
echo $?

The above command when executed in Ubuntu terminal would return


the previous value of the return statement.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation phases: Generation of executable code
for C program
Source Code

Preprocessor
Expanded Code
Compiler
Assembly code
Assembler
Other object files Object code Libraries

Linker

executable code
(In Ubuntu, a.out is called as the executable file)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Data Types
Data Types Memory (bytes) on Range Format Specifier
GCC Compiler
short int 2 -32,768 to 32,767 %hd
unsigned short int 2 O to 65,535 %hu
unsigned int 4 0 to 4,294,967,295 %u
int 4 -2,147,483,648 to %d
2,147,483,647
long int 4 -2,147,483,648 to %ld
2,147,483,647
unsigned long it 4 0 to 4,294,967,295 %lu
long long int 8 -(263 ) 𝑡𝑜 (263 − 1) %lld
unsigned long long int 8 0 to %llu
18,446,744,073,709,551,615

char 1 -128 to 127 %c


unsigned char 1 0 to 255 %c
float 4 3.4E-38 to 3.4E+38 %f
double 8 1.7E-308 to 1.7E+308 %lf
long double 16 3.4E-4932 to 1.1E+4932 %LF
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
printf() function
printf():
• It is primarily used to display or send output to the screen (console).
• #include<stido.h> must be included in a c program that uses scanf()
• The general form of printf() function is:
printf(“format string or message”, list of variables);
Format string can contain:
a) Characters that are simply printed as they are written inside a function
b) Format specifiers that begin with a % sign:
%f for printing real values
%d for printing integer values
%c for printing character values. It can contain other format specifiers as per the type of variables.
c) Escape sequences that begin with a \ sign. For example, \n (for new line)

Note: List of variables need to be used in printf() only if format string specifiers are used.
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
scanf() function
• It is used to read data entered by a user from keyboard.
• #include<stido.h> must be included in a c program that uses scanf()
• The general form of scanf() statement is as follows:
scanf(“format string”, list of addresses of variables);
Format string in scanf can contain:
%f for printing real values
%d for printing integer values
%c for printing character values. It can contain other format specifiers as well as
per the type of variables.
Note: No escape sequences to be used in scanf

For example: scanf(“%d%f%c”,&c,&a,&ch);

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program to print area of a circle for a
given value of a radius
#include<stdio.h>
#define PI 3.14
int main()
{ Output:
int r;
float area;
printf("Enter the value of radius\n");
scanf("%d",&r);
area=PI*r*r;
printf("Area of a circle for a given %d radius is %f",area);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Analogy of Learning English Language and C
Language
Steps in Learning English Language

Alphabets Words Sentences Paragraph

Steps in learning C Language

Alphabets Constants
Instructions
Digits Variables
Or Program
Special Symbols Keywords
Statements

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Alphabets, Digits, and Special Symbols
Alphabets : A, B, C, ….., Y, Z
a, b, c, ……., y, z

Digits : 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Special Symbols : ~ ` @ # % ^ & * ( ) _ - +=| \ { } [ ]: ;” ` <> , . ? / $

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Constants, Variables, and Keywords
The alphabets, digits, and special symbols when properly combined
form Constants, Variables, and Keywords.
Def(Constant): It is an entity that does not change. Constants are often
called Literals in programming languages.

Def(Variables): It is an entity that may change. Variables are called


identifiers.

Def(Keywords): A Keyword is a word that carries special meaning.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Types of Constants

Constants
Our focus
for now is
on
Primary Constants Secondary Constants

Integer Constants Array


Real constants Pointer
Character constant Structure
Union
Enum, etc.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Rules for Constructing Integer Constants
• An integer constant must have at least one digit
• It must not have a decimal point
• It can be any of zero, positive or negative. If no sign precedes an
integer constant, it is assumed to be positive.
• No commas or blanks are allowed within an integer constant.
• The allowable range for integer constants is -2147483648 to
+2147483647.
• Examples of integer constant: 426, +782, -8000, -7605
Note: The range of an integer constant depends upon the compiler.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Suitable Data Types for Integer Constants:
short, int, long
• short, int and long data types can be used to store integer constants.
• The size of short, int and long on GCC compiler are 2, 4 and 4 respectively.
• Each of these data types can be categorized further as signed and unsigned
that results the following data types:
- In the signed version, the highest (leftmost) bit stores the sign of
the number, i.e., 0 if the number is positive and 1 if the number is negative
and the rest of the bits are used to store the value of a number.
- In the unsigned version, all the bits are used to store the value of a
number.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Rules for Constructing Real Constants
• Real constants are often called Floating point constants.
These could be written in two forms:
1) Fractional form:
- A real constant must have at least one digit
- It must have a decimal point
- It can be either positive or negative. Default sign is positive.
- No commas or blanks are allowed within a real constants.
Examples of Fractional form based Real constants are: +325.34,
426.0, -32.76, -48.579

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Rules for Constructing Real Constants (Cont...)
2) Exponential form: It is used if the value of the constant is either too small or too large.
- A real constant in exponential form is represented in two parts.
The part appearing before ‘e’ is called mantissa, whereas the part
following ‘e’ is called exponent.
−4
Thus 0.000342 can be written in
exponential
−4
form as 3.42𝑒 (which is in normal arithmetic means
3.42*10 )
- The mantissa part and the exponential part should be separated by a letter e or E.
- The mantissa part may have a a positive or negative sign. Default sign is
positive.
- The exponent must have at least one digit, whicy may be a positive or
negative integer. Default sign is positive.
- Range of real constants expressed in exponential form is -3.4e38 to 3.4e38.
Examples of real constants in exponential form: +3.2e-5, 4.1e8, -0.2E+3, -3.2e-5.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Suitable Data Types of Real Constants: float,
double, long double
• Float data type occupies 4 bytes in memory and can range from -
3.4e38 to 3.4e38.
• If this is insufficient, then double data type can be used and it
occupies 8 bytes in memory. The double data type has a range from
-1.7e308 to +1.7e308.
• A variable of type double can be declared as follows:
double population;
• long double data type can be used if there is a situation to store a real
number whose size is beyond the size of the double. It occupies 10
bytes in memory and has a range from -1.7e4932 to +1.7e4932.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Difference between float and double data
types
float double
Its size is 4 bytes Its size is 8 bytes
It has 7 decimal digits precision It has 15 decimal digits precision
It may get Precision errors while dealing It will not get precision errors while
with large numbers dealing with large numbers.
For float data type, the format specifier is For double data type, the format specifier
%f. is %lf.
For example -: 3.1415 For example -: 5.3645803
It requires less memory space as It needs more resources such as
compared to double data type. occupying more memory space in
comparison to float data type.
It is suitable to use in the programming
It is suitable in graphics libraries for
language to prevent errors while
greater processing power because of its
rounding off the decimal values because
small range.
of its wide range.
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Rules for Constructing Character Constants
- A character constant can be a:
- Single alphabet
- Single Digit
- Single special symbol (e.g., &, $, #,=, etc.)
- Character constant must be enclosed within single inverted commas.
Examples of Character Constants: ‘A’, ‘I’, ‘5’, ‘=‘

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Suitable data type for character constant: char
Example of a character variable declaration and initialization:
char ch=‘A’;
It is to be noted that the binary equivalent of the ASCII/Unicode value of ‘A’
(i.e., binary 65) gets stored in ch.
• As with integers, signed is default. So signed char is same as char and has a
range from -128 to +127. Likewise, an unsigned char has a range from 0 to
255.
Note: while assigning a value to an integer or a char, it it exceeds the upper
bound, then the appropriate value from negative side of the ranges get
assigned. Similarly, if the lower bound is exceeded, then the value from the
positive side of the range gets assigned.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program on char data ranges.
CharRange.c
#include<stdio.h>
int main()
{
char ch=128;
char dh=-132;
printf("%d\t%d\n",ch,dh);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution
Compilation on Ubuntu OS
gcc CharRange.c -o CharRange
// The above compilation commands creates Sample4 executable after
successful compilation.

Output
Execution:
./CharRange

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Variables
• A variable is a name given to a memory location so that it can be used
to store a data value.
• As the value stored in each location may change, the names given to
these locations are called variables.
• A variable can take different values but one at a time. These values
can be changed during execution of the program.
• A particular type of variable can hold only the same type of constant.
For example, an integer variable can hold only an integer constant

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Variables (Cont…)

Rules for Constructing Variable names:


- A variable name is any combination of alphabets, digits, or underscores.
- The first character in the variable name must be an alphabet or underscore(_) .
- Uppercase and lowercase letters are permitted.
- Variable names cannot be keywords.
- Variable names should not contain white space.
Note: Do not create unnecessary long variable names as it adds to your typing
effort.
Examples of variable names: si_int, pop_e_89, avg, basic_salary.
Note: Always create meaningful variables names for the variables.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Variable Declaration and Usage
• Any variable must be declared and initialized before it is used.
• Declaration of a variable includes specification of variable name and its data type.
Syntax of variable declaration:
datatype variablename:
• Variable initialization: When a variable is declared it contains undefined value called as garbage
value. The process of assigning our own value to a variable is called initialization.
Example is provided below:
int n; //Declaration
float r, si; // declaration
int p=2000; // Variable declaration and initialization
n=24; // Variable initialization
r=2; // Variable initialization
si=(p*n*r)/100// usage

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Keywords
• Keywords are the words whose meaning has already been explained
to the C Compiler.
• There are only 32 keywords available in C that are provided below.

Note: Keywords should not be used as variable names.


DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Backslash Character Constants (Escape Character
Sequences)
• C supports backslash character contants that are used in output functions.
• They are also called as Escape Character sequences because when a character is preceded
by a backslash (\), it is called an escape sequence and it has a special meaning to the
compiler.
Constant Meaning
‘\a’ Audible alert (bell)
‘\b’ Back space
‘\f’ Form feed
‘\n’ New line
‘\r’ Carriage return
‘\t’ Horizontal tab
‘\v’ Vertical tab
‘\’’ Single quote
‘\”’ Double quote
‘\?’ Question Mark
‘\\’ Backslash
‘10’ null
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Sample Program 1
Write a C program to accept two integer numbers from user and
display their product.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
int main()
{
int n1, n2, prod;
printf("Enter value for n1\n");
scanf("%d",&n1);
printf("Enter value for n2\n");
scanf("%d",&n2);
prod=n1*n2;
printf("The product of two numbers is %d",prod);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program 2
Write a C program to accept two real numbers and display their sum.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution 2
#include<stdio.h>
int main()
{
float n1, n2, sum;
printf("Enter value for n1\n");
scanf("%f",&n1);
printf("Enter value for n2\n");
scanf("%f",&n2);
sum=n1+n2;
printf("The sum of two real numbers is %f",sum);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program 3
Write a C program to accept an integer number, real number and a
character and display each of them in a separate line.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution Sample3.c
#include<stdio.h>
int main()
{
int n;
float f;
char ch;
printf("Enter value for n\n");
scanf("%d",&n);
printf("Enter value for f\n");
scanf("%f",&f);
printf("Enter value for ch\n");
scanf(" %c",&ch);
printf("The entered integer value is %d",n);
printf("The entered real value is %f",f);
printf("The entered character value is %c",ch);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution
Compilation on Ubuntu OS
gcc Sample3.c -o Sample3
// The above compilation commands creates Sample3 executable after
successful compilation.

Execution:
./Sample

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program 4
Write a C program to accept an integer number, real number and a
character using a single scanf() function and display each of them
using a single printf() function.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program 4
Sample4.c
#include<stdio.h>
int main()
{
int n;
float f;
char ch;
printf("Enter values for integer n float f and character c\n");
scanf("%d%f %c",&n,&f,&ch); // observe space in scanf() function before %c.
printf("The entered integer value is %d Float value is %f Character value is %c",n,f,ch);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution
Compilation on Ubuntu OS
gcc Sample4.c -o Sample4
// The above compilation commands creates Sample4 executable after
successful compilation.

Execution:
./Sample4

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program demonstration on char data
type CharDemo.c

#include<stdio.h>
int main()
{
char ch='A';
ch=ch+2;
printf("The value of a character after adding 2 is %c\n",ch);
printf("The character calue in integer value form is %d\n",ch);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution
Compilation on Ubuntu OS
gcc CharDemo.c -o CharDemo
// The above compilation commands creates Sample4 executable after
successful compilation.

Output
Execution:
./CharDemo

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program 1
Write a C program to calculate an employee’s gross pay salary. The
basic salary of a employee needs to be entered by an employee for
which you need to determine the gross pay based on DA, which is 40%
and HRA, which is 20%

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution C Program
Lab11.c

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Compilation and Execution
Compilation on Ubuntu OS
gcc Lab1.c -o Lab1
// The above compilation commands creates Lab1 executable after
successful compilation.

Execution: Output

./Lab1

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program 2
Assume that the marks obtained by a student in five different subjects are given as
input through the keyboard. write a C program to find out Total marks, Average
marks and percentage of the marks obtained by the student. Assume that the
maximum marks a student can obtain in each subject is 100.
Test case:
Input:
Enter marks for five subjects
43 71 75 45 73
Output:
Total: 307.000000
Average: 61.400002
Percent: 61.400002

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
int main() Lab2.c
{
float eng,phy,chem,math,tel;
float total,average,percent;
printf("Enter marks of five subjects:\n");
scanf("%f%f%f%f%f",&eng,&phy,&chem,&math,&tel);
total=eng+phy+chem+math+tel;
average=total/5;
percent=(total/500)*100;
printf("Total marks: %f \n",total);
printf("Average marks: %f \n",average);
printf("Percentage: %f \n ",percent);
return 0;
}
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Compilation and Execution
Compilation on Ubuntu OS
gcc Lab2.c -o Lab2
// The above compilation commands creates Lab2 executable after
successful compilation.
Output

Execution:
./Lab2

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Some more problems
1. Write a c program to accept temperature of a city in Fahrenheit
degrees (through keyboard) and convert it into Celsius degrees.
Test case1:
Input: 32
Output: 0

Test Case2:
Input:100
Output:37.777779

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Formula for Temperature Conversion from
Fahrenheit to Celcius

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Some more problems (Cont…)
2.Write a C program to convert given hours (integer value) and convert
it into minutes and seconds.
Test case:
Input:
Enter hours
5
Output:
Minutes: 300
Seconds: 18000

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Operators
• C supports a rich set of built-in operators.
• Any operator is a symbol that tells the computer to perform certain
mathematical or logical manipulations.
• Operators are used in programs to manipulate data and variables.
• C operators can be classified into following categories:
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and Decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
1. Arithmetic operators
Operator Meaning Example: a=2, b=3
+ Addition or Unary Plus
- Subtraction or Unary minus
* Multiplication
/ Division
% Modulo Division (produces the
remainder after division)
• These can operate on any built-in data type allowed in C.
• Examples of expressions involving arithmetic operators:
a-b, a+b, a*b, a%b, a/b, -a*b
Here, a and b are operands

Note: % cannot be used on floating point data (Real data).

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Integer Arithmetic
• When arithmetic expressions includes integer operands, that expression is
called integer expression and the operation is called integer arithmetic.
• Integer arithmetic always yields an integer value.
• The largest value depends on the machine based on data types.
For example: a=14, b-4
a-b=10
a+b=18
a*b=56
a/b=3 (Decimal part truncated)
a%b=2 (Remainder of division)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program on Relational Operators
// Working of arithmetic operators
#include <stdio.h>
int main()
{
int a = 9,b = 4, c;

c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);

return 0;
}
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Real Arithmetic
• An arithmetic operation involving real operands is called real
arithmetic.
Example of Real arithmetic expression:
x=6.0/7.0
The x value would be 0.857143
• A real operand may assume values either in decimal or exponential
notation.
• Since floating point values are rounded to the number of singinificant
digits permissible, the final value is an approximation of the correct
result.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


2. Relational operators
Relational operators can be used to compare two values or two quantities. Depending on the
outcome of comparison, certain decisions can be taken.
Relational Operator Meaning Example: a=2, b=3

< Is less than a<b


True, i.e., returns 1
<= Is less than or equal to a<=b
True, i.e., returns 1
> Is greater than a>b
False, i.e., returns 0
>= Is greater than or equal to a>=b
False, i.e., returns 0
== Is equal to a==b
False, i.e., returns 0
!= Is not equal to a!=b
True, i.e., returns 1
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
3. Logical Operators
Logical operators are used to test more than one condition and make decisions.

Operator Meaning
&& Logical And
|| Logical Or
! Logical Not

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Output of Logical Operators (Expression)
OP1 OP2 OP1 && OP2 OP1||OP2

Non-Zero Non-Zero 1 1

Non-Zero 0 0 1

0 Non-Zero 0 1

0 0 0 0

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


#include <stdio.h>
int main()
{
int a = 5, b = 5, c = 10, result; Example program on Logical Operators

result = (a == b) && (c > b);


printf("(a == b) && (c > b) is %d \n", result);

result = (a == b) && (c < b); Output


printf("(a == b) && (c < b) is %d \n", result);

result = (a == b) || (c < b);


printf("(a == b) || (c < b) is %d \n", result);

result = (a != b) || (c < b);


printf("(a != b) || (c < b) is %d \n", result);

result = !(a != b);


printf("!(a != b) is %d \n", result);

result = !(a == b);


printf("!(a == b) is %d \n", result);

return 0;
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
}
Expressions and Theirs outputs
Expression Output

-14%3 -2
14%-3 -2
15/10.0 1.5
15/10 1
Suppose a=2, b=3, c=1, 0
Then the value of (a>b) && (a>c)
Suppose a=2, b=3, c=1, 1
Then the value of (a<b) && (c<a)

Suppose a=2, b=3, c=1, 1


Then the value of (a<b) || (a<c)

Suppose a=2, b=3, c=1, 0


Then the value of (a>b) || (a<c)
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
4. Assignment Operator (=)
• The assignment operator, i.e., = (equals sign) is used to assign the result of an expression or value
of a variable to a variable.
v=a;
or
v=exp;
Here, v is a variable and exp can be any expression of the form like a+b,a-b, etc.

• Shorthand Notation: C also supports shorthand assignment operators that is shown below.
v op=exp;// This is known as shorthand operator.
The above is equivalent to
v= v op exp;
here, v is a variable, exp is an expression, and op is an arithmetic operator.
Note: Shorthand notation can be used with all arithmetic operators.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Shorthand notation examples
1) int a = 20 ;
a += 10 ; // It means a = a + 10 ,
printf(“%d”,a);
Output is 30
2) int z = 10 ;
z *= 10 ; // It means z = z * 10 ,
printf(“%d”,z);
Output is 100
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Example program on Assignment operator
#include <stdio.h>
int main()
{
int a = 5, c;
c = a; // c is 5
printf("c = %d\n", c);
c += a; // c is 10
printf("c = %d\n", c);
c -= a; // c is 5
printf("c = %d\n", c);
c *= a; // c is 25
printf("c = %d\n", c);
c /= a; // c is 5
printf("c = %d\n", c);
c %= a; // c = 0
printf("c = %d\n", c);
return 0;
}
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
5. Increment (++) and Decrement (--)
Operators
• The increment operator ++ is used to increment the value of the
given variable or operand by 1. In other words, it adds value 1 to the
existing operand’s value.
• The decrement operator -- is used to decrement the value of a given
variable by 1. In other words, it subtracts value 1 from the operand’s
to value.
• These operators are also called as Unary operators as they operator
on the value of a single operand.
Note: Operand can also be referred to as variable.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Usage of Increment and Decrement operators
Increment and Decrement operators can be classified further based on
usage in expressions. The classifications are provided berlow.
• Prefix Increment operator (++v)
• Postfix Increment operator(v++)
• Prefix Decrement operator (--v)
• Postfix Decrement operator(v--)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


5. Increment (++) and Decrement (--)
Operators (Cont…)
• The pre-increment (++v) and post-increment (v++) behave differently when they are used in
expressions on the right-hand of an assignment statement.

• A prefix operator first adds 1 to the operand and then the result is assigned to the variable on
left.
• For example:
v=5;
y=++v;
Here, the value of y would be 6 and v would be 6.
• A postfix operator first assigns the value to the variable on left and then increments the
operand. Example is provided below.
v=5;
y=v++;
Here, the value of y would be 5 but the value of v would be 6 (due to post increment).

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


5. Increment (++) and Decrement (--)
Operators (Cont…)
• The pre-decrement (--v) and post-decrement (v++) behave differently when they are
used in expressions on the right-hand of an assignment statement.
• A prefix decrement operator first decrements 1 from the operand and then the result is
assigned to the variable on left.
For example:
v=5;
y=--v;
Here, the value of y would be 4 and v would be 4.
• A postfix decrement operator first assigns the value to the variable on left and then
decrements the operand. Example is provided below.
v=5;
y=v--;
Here, the value of y would be 5 but v would be 4 (due to post decrement)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Rules for Increment (++) and Decrement (--)
operators
• Increment and Decrement operators are unary operators and they
require variable as their operands.
• When postfix ++ (or --) is used with a variable in expression, the
expression is evaluated first using the original value of the variable
and then the variable is incremented (or decremented) by one.
• When prefix ++ (or --) is used in expression, the variable is
incremented (or decremented) first and then the expression is
evaluated using the new value of the variable.
• The precedence and associativity of ++ and – operators are the same
as that of unary + and unary -.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program on Increment and
Decrement operators
#include <stdio.h>
int main()
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;

printf("++a = %d \n", ++a);


printf("--b = %d \n", --b);
printf("++c = %f \n", ++c);
printf("--d = %f \n", --d);

return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


6. Conditional Operator (?:)
• The conditional operator is also known as a ternary operator as it
takes three operands to work.
• Syntax :
Note: Variables also can be present in
place of expression

• The result is based on


the outcome of the expressions.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Execution flow of ternary operator

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example of Ternary operator
a=10;
b=15;
x=(a>b) ? a:b;
Here, x would be assigned value of b the condition a>b is false. Hence,
the variable x would hold the value 15.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Another Example program on ternary operator
#include <stdio.h>
int main()
{
int a=5,b; // variable declaration
b=((a==5)?(3):(2)); // conditional operator
printf("The value of 'b' variable is : %d",b);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


7. BITWISE Operators
• The BITWISE operators are used to perform operations on the data at
bit level.
• These operators could be used for testing the bits or shifting them
right or left.

Note: Bitwise operators may not be applied to float or double.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


7. BITWISE Operators (Cont…)
Operator Meaning Example (a=5, b=9)
& Bitwise AND. The result of AND is 1 only if both bits a&b
are 1 It produces output 1
| Bitwise OR. The result of OR is 1 if any of the two a|b
bits is 1 It produces 13
^ Bitwise exclusive OR. The result of XOR is 1 if the a^b
two bits are different. It produces 12

<< Shift left. Here, this operator left shifts the bits of b<<1
the first operand, the second operand decides the It produces 18
number of places to shift.

>> Shift right. Here, this operator right shifts the bits of b>>1
the first operand, the second operand decides the It produces 4
number of places to shift.

~ Bitwise NOT. It inverts bits. ~a=-6


DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
#include <stdio.h>
int main()
{ Example program on BITWISE Operators
// a = 5(00000101), b = 9(00001001)
char a = 5, b = 9;

// The result is 00000001


printf("a = %d, b = %d\n", a, b);
printf("a&b = %d\n", a & b);
Output
// The result is 00001101
printf("a|b = %d\n", a | b);

// The result is 00001100


printf("a^b = %d\n", a ^ b);

// The result is 11111010


printf("~a = %d\n", a = ~a);

// The result is 00010010


printf("b<<1 = %d\n", b << 1);

// The result is 00000100


printf("b>>1 = %d\n", b >> 1);

return 0;
} DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
8. Special Operators
• C supports some of the special operators. Two of them provided
below.
i. comma operator (,)
ii. sizeof() operator

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


8. Special Operators (Cont…)
i. Comma operator (,):
• It can be used to link the related expressions (or variables) together.
• A comma-linked list of expressions are evaluated from left to right and the
value of right-most expression is the value of the combined expression.
• It can be used in for loops, while loops and for exchanging values as well.
Example 1:
v=(x=10,y=5,x+y)
Here, it value 10 is assigned to x, then assigns 5 to y and finally assigns 15
(,i.e., 10+5) to v.
Example 2:
t=x, x=y, y=t;

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


8. Special Operators (Cont…)
ii. sizeof:
- It is a compile time unary operator which can be used to compute the size of its
operand.
The operand can be a variable, a constant, or a data type qualifier (int, float,
etc.)
- The sizeof operator is normally used to determine the lengths of arrays and
structures when their sizes are not known to the programmer.
Example:
int a=2;
m=sizeof(a)
n=sizeof(long int)
k=sizeof(235L)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to find out the biggest of two numbers
(entered through keyboard) using ternary operator.
Test case 1:
Input: 4 5
Output: 5

Test case 2:
Input: 10 -20
Output: 10

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to convert an upper-case character to a lower-case
character.

Test Case 1:
Input: A
Output: a

Test Case 2:
Input: E
Output: e

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution:
#include <stdio.h>
int main()
{
char uc,lc;
printf("Enter character in upper case \n");
scanf("%c",&uc);
lc=uc+32;
printf("The lower case character after conversion is %c",lc);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to swap values of two variables

Test Case 1:
Inputs of a and b before swapping are: 5 6
Output of a and b after swapping are: 6 5

Test Case 2:
Inputs of a and b before swapping are: 19 20
Output of a and b after swapping are: 20 19

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to swap values of two variables without using any
temporary variable

Test Case 1:
Inputs of a and b before swapping are: 5 6
Output of a and b after swapping are: 6 5

Test Case 2:
Inputs of a and b before swapping are: 19 20
Output of a and b after swapping are: 20 19

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to display remainder of two numbers after
performing division operation without using modulus (%) operator.
Test case 1:
Input: 14 5
Output: 4

Test case 2:
Input: 14 8
Output: 6

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include <stdio.h>
int main()
{
int a,b,r,m,q;
printf("Enter value for a and b \n");
scanf("%d%d",&a,&b);
q=a/b;
printf("%d",q);
m=q*b;
r=a-m;
printf("The remainder of %d and %d after divison without using modulus oeprator is %d",a,b,r);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


math.h header file
• math.h header file contains pre-defined mathematical functions that
can be used to perform mathematical operations.
• All the functions available in this library take double as an argument
and return double as the result.
For example1:
double d=pow(3,2)
this functions returns the value 32 ,i.e., 9.000000

Example 2:
int i=pow(5,2), returns the value 52 ,i.e., 25
Note:When integer is used to assign the result of math function, then the
result (decimal part) will be truncated to integer value.
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Functions of math.h header file
Function Meaning Examples
ceil(x) It rounds up the given value and returns the i. ceil(1.6) returns 2.0
smallest integer value greater than or equal ii. ceil(1.2) returns 2.0
to x.
floor(x) It rounds down the given value and returns floor(1.6) returns 1.0
the largest integer value less than or equal floor(1.2) returns 1.0
to x
fabs(x) It returns the absolute value of x. fabs(1234) returns 1234.0
fabs(-4) returns 4.0
log(x) It returns the natural logarithm (base-e log(2.7) returns 0.993252
logarithm) of x.
Note:#include<math.h> must be included in your C program when you the above
functions in your program DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Functions of math.h header file
Function Meaning Examples
log10(x) It returns the common logarithm (base-10 log10(10000) returns 4.0
logarithm) of x.
fmod(x) It returns the remainder of x divided by y. fmod(8.2,5.7) returns
2.500000
sqrt(x) It returns the square root of x Sqrt(225) returns 15
Sqrt(300.0) returns
17.320508
pow(x,y) It returns x raised to the power of y, i.e., 𝑥 𝑦 pow(8,3) returns 24.0
Pow(3.05, 1.98) returns
9.097324

Note:#include<math.h> must be included in your C program when you the above


functions in your program
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Example program that uses math.h functions
#include<stdio.h>
#include<math.h>
int main()
{ Output
double a=1.6,b=-5.0,c=3.0,d=4.0,e=225.0;
printf("Ceil function output is %lf\n",ceil(a));
printf("Floor function output is %lf\n",floor(a));
printf("Absolute function output is %lf\n",fabs(b));
printf("Power function output is %lf\n",pow(c,d));
printf("Square root function output is %lf",sqrt(e));
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to calculate Simple and Compound interest for various parameters specified by
the user. The parameters are given below:
t – Time span in years
P – Principal amount in rupees.
R – Rate of interest in percent
Test case
Input:
P: 500000
T: 2
R: 12
Output:
The simple interest is 120000.000000
The compound interest is 127200.000000

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Formulae

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
#include<math.h> // Calculating compound Interest
int main() double Amount = principal * ((pow((1 + rate / 100), time)));
{ double CI = Amount - principal;// compuound interst
// Principal amount
double principal; printf("Compound Interest is : %lf\n",CI);
// Annual rate of interest return 0;
double rate; }

// Time
double time;
printf("Enter principal amount");
scanf("%lf",&principal);
printf("Enter rate of interest\n");
scanf("%lf",&rate);
printf("Enter time in years");
scanf("%lf",&time);
double si=(principal*time*rate)/100;// simnple interst
printf("The simple interest is %lf\n",si);

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Operator Precedence and Associativity
• Each operator in C has a precedence and associativity.
Precedence (Or Rank or Precedence)
• The precedence is a number that is used to determine how an expression
involving more one than one operator is evaluated. Rank 1 indicates the
highest precedence level and 15 indicates the lowest precedence.
• There are distinct levels of precedence and an operator may belong to one
of those values.
• The operators of the same precedence are evaluated either from ‘Left to
Right’ or ‘Right to Left’ depending on the level. This is known as the
associativity property of an operator.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Operator Precedence and Associativity
(Cont…)
• Precedence rules decides the order in which different operators
applied.
• Associativity rule decides the order in which multiple occurrences of
the same level operator are applied.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Associativity of Operators
Operator Description Associativity Rank (or
Precedence)
() Function expression Left to Right 1
[] Array Expression Left to Right 1
-> Structure Operator Left to Right
. Structure Operator Left to Right
+ Unary Plus Right to Left 2

- Unary Minus Right to Left 2


++ Increment Right to Left 2
-- Decrement Right to Left 2
~ One’s Complement Right to Left 2
! Negation Right to Left 2
& Address of Right to Left 2
* Value at address (or Pointer Reference). Right to Left 2
Example, *a, *b,*c, etc. DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Associativity of Operators (Cont…)
Operator Description Associativity Rank (or
Precedence)
* Multiplication Left to Right 3
/ Division Left to Right 3
% Modulus Left to Right 3
+ Addition Left to Right 4
- Subtraction Left to Right 4
<< Left Shift Left to Right 5
>> Right Shift Left to Right 5
< Less than Left to Right 6
<= Less than or equal Left to Right 6
to
> Greater than Left to Right 6
>= Greater than Left to Right 6
== Equal to Left to Right 7
!= Not equal to Left to Right 7 DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Associativity of Operators (Cont…)
Operator Description Associativity Rank (or
Precedence)

& Bitwise AND Left to Right 8


^ Bitwise exclusive Left to Right 9
OR
| Bitwise OR Left to Right 10
&& Logical AND Left to Right 11
|| Logical OR Left to Right 12
?: Conditional Right to Left 13
= Assignment Right to Left 14
*= /= %=
+= -+ &=
^= |=
<<= >>=
, Comma Right to Left 15
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Evaluation of Expressions of without
parentheses
• An arithmetic expression without parenthesis will be evaluated from left to
right using the rules of precedence of operators.
There are two distinct priority levels of arithmetic operators in C:
High Priority: * / %
Low Priority: + -
• The basic evaluation of expression includes two left-to-right passes through
the expression.
- During the first pass, the high priority operators (if any) are applied
as they are encountered.
- During the second pass, the low priority operators (if any) are
applied as they are encountered.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example
Assume that a=9, b=12, and c=3
x= a-b/3+c*2-1
The above statements becomes as shown below
x=9-12/3+3*2-1

First Pass: Second Pass:


iii) x=5+6-1
i) x=9-4+3*2-1
iv) x=11-1
ii) x= 9-4+6-1 v) x=10

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Evaluation of Expression with Parenthesis
• Whenever parentheses are used, the expressions within parentheses
assume highest priority.
• If two or more sets of parentheses appear one after another, the
expressions contained in the left-most set is evaluated first and the
right-most in the last.
• When parentheses are nested, the evaluation of expression will
proceed outward from the innermost set of parentheses.
• Consider the example below for evaluation:
9-12/(3+3)*(2-1)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Expression with parentheses
• The evaluation of below expression:
9-12/(3+3)*(2-1)
First Pass:
i) 9-12/6*(2-1)
ii) 9-12/6*1
Second Pass:
iii) 9-2*1
iv) 9-2
v) 7
The result is 7 after the evaluation of 9-12/(3+3)*(2-1)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Expression with nested-parentheses
• The evaluation of below expression:
9-(12/(3+3)*2)-1)
The result is 4
• The evaluation of below expression:
9-((12/3)+3*2)-1
The result is -2

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Associativity of Operators (Cont…)
Consider below another example:
a=b=3;
Here, both assignment operators have priority. So order of operations
is decided using associativity of = (equals) operator.
- The = (equals) operator associativity is Right to Left. Therefore, first
b=3 takes place and then a=b takes place.
-

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Associativity of Operators (Cont…)
Consider another example:
z= a*b+c/d;
- The operators* and / enjoys same priority and same associativity
(Left to Right)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Importajnt Rules for Evaluation of Expression
• First, parenthesized sub expression from left to right are evaluated.
• If parentheses are nested, the evaluation begins with the innermost
sub-expression.
• The precedence rule is applied in determining the order of application
of operators in evaluating sub-expressions.
• The associativity rule is applied when two or more operators of the
same precedence level appear in a sub-expression.
• Arithmetic expressions are evaluated from left to right using the rules
of precedence.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program
Write a C program to evaluate the following equations.
x=a*b-c
y=b/c*a
z=a-b/c+d
Where the values of a, b and c are to be entered through keyboard.
Test case:
Input values for a, b, c and d: 9, 12, 3, 2
Output:
x: 105.000000
y: 36.000000
z: 7.000000

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
int main()
{
float a, b, c, d, x, y, z;
printf("Enter value for a\n");
scanf("%f",&a);
printf("Enter value for b\n");
scanf("%f",&b);
printf("Enter value for c\n");
scanf("%f",&c);
printf("Enter value for d\n");
scanf("%f",&d);
x=a*b-c;
y=b/c*a;
z=a-b/c+d;
printf("x=%f\n",x);
printf("y=%f\n",y);
printf("z=%f\n",z);
return 0;
} DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Sample Program
Write a C program to evaluate the following equations.
x=a-b/3+c*2-1
y=a-b/(3+c)*(2-1)
z=a-(b/(3+c)*2)-1
Where the values of a, b and c are to be entered through keyboard.
Test case:
Input values for a, b, and c: 9, 12, 3
Output:
x: 10.000000
y: 7.000000
z: 4.000000

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
int main()
{
float a, b, c, x, y, z;
printf("Enter value for a\n");
scanf("%f",&a);
printf("Enter value for b\n");
scanf("%f",&b);
printf("Enter value for c\n");
scanf("%f",&c);
x=a-b/3+c*2-1;
y=a-b/(3+c)*(2-1);
z=a-(b/(3+c)*2)-1;
printf("x=%f\n",x);
printf("y=%f\n",y);
printf("z=%f\n",z);
return 0;
}
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
Type Conversion (or Type Casting)
• A type cast is basically a conversion from one type to another.
• Type conversion is also known as Type casting.
• It helps us to obtain results with high precision.
There are two types of type conversion:
1. Implicit Type Conversion
2. Explicit Type Conversion

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


1. Implicit Type Conversion
• Also known as ‘automatic type conversion’.
• Done by the compiler on its own, without any external trigger from the
user.
• If the operands are of two different data types, then an operand having
lower data type is automatically converted into a higher data type. This
type of type conversion can be seen in the following example.
• Generally takes place when in an expression more than one data type is
present. In such condition type conversion (type promotion) takes place to
avoid loss of data.
• All the data types of the variables are upgraded to the data type of the
variable with largest data type.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


1. Implicit Type Conversion (Cont…)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example
#include <stdio.h>
int main() { Output:
int number = 1; Value of sum : 108

char character = 'k'; /*ASCII value is 107 */


int sum;
sum = number + character; //implicit conversion happens
printf("Value of sum : %d\n", sum );
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Few more Examples of Implicit Conversion
Examples:

bool x = true;
char y = ‘X’;
int i = 123;
Long double d = 1234.5;

y = x; // value of y is 1 (ASCII)
i = y; // value of i is 88
d = x; // value of d is 1.0
d = i; // value of d is 1234.0

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program on Implicit Conversion
#include<stdio.h>
int main()
{
int x = 10; // integer x
char y = 'a'; // character c
// y implicitly converted to int. ASCII
// value of 'a' is 97 Output:
x = 107, z = 108.000000
x = x + y;

// x is implicitly converted to float


float z = x + 1.0;

printf("x = %d, z = %f", x, z);


return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Another Example program on Implicit Conversion

Output:

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


2. Explicit Type Conversion
• This process is also called type casting and it is user defined.
• Here the user can manually type cast the result to make it of a
particular data type.
• The syntax in C:
(type) expression
Type indicated the data type to which the final result is to be
converted.
An expression can be a constant, a variable or an actual expression.
• It is useful to obtain results without any data loss while evaluating
exxpressions.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


2. Explicit Type Conversion (Cont…)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


What is the output?.
int a=5,b=3;

float f=a/b;
printf("%f",f);

Output:
1

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


What is the output?.
int a=5,b=3;

float f=(float)a/b;
printf("%f",f);

Output:
1.666667

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Example program on Explicit Conversion
#include<stdio.h>

int main()
{
double x = 1.2;
Output:
sum =2
// Explicit conversion from double to int
int sum = (int)x + 1;

printf("sum = %d", sum);

return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Another Example program on Explicit
Conversion
#include<stdio.h>
int main()
{
float a = 1.2;
//int b = a; //Compiler will throw an error for this
int b = (int)a + 1;
printf("Value of a is %f\n", a); Output:
Value of a is 1.200000
printf("Value of b is %d\n",b); Value of b is 2
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C Program to print Least Significant Bit (LSB) of a given number.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include <stdio.h>
int main()
{
int n;
printf("Enter value\n");
scanf("%d",&n);
int a=n&1;
printf("LSB is %d",a);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C Program to display nth bit of the given number.

(hint: Use bitwise operators)

Testcase1:
Input:
Enter value of a number:10
Enter kth bit value: 4
Output:
1

Note: Binary value of 10 is 1010


The 4th bit is 1. Hence, the output is 1.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
#include<math.h>
int main()
{
int number,k,result;
printf("Enter number\n");
scanf("%d",&number);
printf("Enter kth bit value\n");
scanf("%d",&k);
result=number&(1<<k-1);
printf("The value of the kth bit is %d",result>>k-1);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Lab Program
Write a C program to find third angle of triangle for the given two angles
(Entered by a user through keyboard).

Test case:
Input
Enter First Angle: 60
Enter Second Angle: 80

Output
Third Angle: 40

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Properties of a Triangle
• Sum of angles of a triangle is 180°
• If two angles of a triangle are given,
then third angle of triangle can be obtained using
the below formula:
c= 180° - (a+b)

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
int main()
{
int a,b, c;
printf("Enter two angles\n");
scanf("%d%d",&a,&b);
c=180-(a+b);
printf("The third angle is %d",c);
return 0;
}

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Sample Program
Write a C program to accept the length and breadth of a rectangle and the radius of
a circle and then calculate and display the area and perimeter of the rectangle, and
also display the area and circumference of the circle.
Test case:
Input
Enter length and breadth of a rectangle: 4 5
Enter radius of a circle: 1
Output
Area of a rectangle: 20
Perimeter of a rectangle: 18
Area of a circle: 3.14
Circumference of a circle: 6.28

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Formulae
• The perimeter P of a rectangle is given by the formula, P=2(l+w) ,
where l is the length and w is the width of the rectangle.
• The area A of a rectangle is given by the formula, A=lw , where l is
the length and w is the width.
• Area of a circle: π𝑟 2
• Circumference of a circle: 2πr

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd


Solution
#include<stdio.h>
#include<math.h>
int main()
{
double length,breadth,radius;
double pi=3.14;
double area_rectangle,area_circle;
double peri_rectangle, circum_circle;
printf("Enter length and breadth of a rectangle\n");
scanf("%lf%lf",&length,&breadth);
printf("Enter Radius of a circle\n");
scanf("%lf",&radius);
area_rectangle=length*breadth;
peri_rectangle=2*(length+breadth);
printf("Area of a rectangle is %lf\n",area_rectangle);
printf("Perimeter of a rectange is %lf\n",peri_rectangle);
area_circle=pi*radius*radius;
circum_circle=2*pi*radius;
printf("Area of a cicle is %lf\n",area_circle);
printf("The circumference of a circle is %lf\n",circum_circle);
return 0;
}
DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd
References
1. B. A. Forouzan and R. F. Gilberg, Computer Science: A
Structured Programming Approach Using C, 3/e, Cengage
Learning, Third Edition
2. Jeri R Hanly, Elliot B Koffman, Problem Solving and Program
Design in C, 7/e, Pearson Education, 2012.
3. Let Us C by Yashawanth Kanetkar, 15 Edition.
4. Programming in ANSI C, Seventh Edition by E
Balaguruswamy, 2017
5. Online sources: GeeksforGeeks, Tutorialpoint, JavatPoint, etc.

DVN Siva Kumar, Asst Prof, CSE Dept, GITAM Hyd

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy