0% found this document useful (0 votes)
3 views36 pages

Introduction to C Programming Concepts

Uploaded by

factsr631
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)
3 views36 pages

Introduction to C Programming Concepts

Uploaded by

factsr631
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

STRUCTURED PROGRAMMING USING C UNIT - I

MODULE -I
INTRODUCTION TO C

• A computer is a powerful and versatile machine capable of performing a different task, yet it has no
intelligence or thinking power. The intelligence Quotient (I.Q) of a computer is zero

• A computer performs many tasks exactly in the same manner as it is told to do.

• This places responsibility on the user to instruct the computer in a correct and precise manner, so that
the machine is able to perform the required job in a proper way.

• In order to instruct a computer correctly, the user must have clear understanding of the problem to
be solved

• Once the problem is well-defined and a method of solving it is developed, then instructing the
computer to solve the problem becomes relatively easier task.

• Before attempt to write a computer program to solve a given problem. It is necessary to formulate
or define the problem in a precise manner

Steps Involved in Problem Solving:

• A computer cannot solve a problem on its own. One has to provide step by step solutions of
the problem to the computer

• It is the programmer who has to write down the solution to the problem in terms of simple
operations which the computer can understand and execute.

• Steps to follow in order to solve a problem by the computer


1. Understanding the problem
2. Analysing the problem
3. Developing the solution
4. Coding and implementation.

1. Understanding the problem: Here we try to understand the problem to be solved in totally.
Before with the next stage or step, we should be absolutely sure about the objectives of the given
problem.
2. Analysing the problem: After understanding thoroughly the problem to be solved, we look
different ways of solving the problem and evaluate each of these methods. The idea here is to search

Page 1
STRUCTURED PROGRAMMING USING C UNIT - I

an appropriate solution to the problem under consideration. The end result of this stage is a broad
overview of the sequence of operations that are to be carries out to solve the given problem.
3. Developing the solution: Here the overview of the sequence of operations that was the result of
analysis stage is expanded to form a detailed step by step solution to the problem under consideration.

4. Coding and implementation: The last stage of the problem solving is the conversion of the detailed
sequence of operations in to a language that the computer can understand. Here each step is converted
to its equivalent instruction or instructions in the computer language that has been chosen for the
implantation.

Problem solving approaches:

Algorithmic Approach

Definition:

A set of sequential steps usually written in Ordinary Language to solve a given problem is called
Algorithm.

OR

An algorithmic approach is a method of solving a problem by designing step-by-step procedure (an


algorithm) that can be followed to complete a task.

In other words:

❖ You break the problem down into a sequence of logical steps.


❖ These steps are defined clearly.
❖ They can be carried out by a human, or by a computer, or by both.

Steps involved in the development of algorithm:

An algorithm can be defined as “a complete, unambiguous, finite [Link] logical steps for solving a
specific problem “

Step1. Identification of input: For an algorithm, there are quantities to be supplied called input
and these are fed externally. The input is to be identified first for any specified problem.

Step2: Identification of output: From an algorithm, at least one quantity is produced, called for
any specified problem.

Step3 : Identification the processing operations: All the calculations to be performed in order
to lead to output from the input are to be identified in an orderly manner.

Page 2
STRUCTURED PROGRAMMING USING C UNIT - I

Step4: Processing Definiteness: The instructions composing the algorithm must be clear and
there should not be any ambiguity in them.

Step5: Processing Finiteness: If we go through the algorithm, then for all cases, the algorithm
should terminate after a finite number of steps.

Step6: Possessing Effectiveness: The instructions in the algorithm must be sufficiently basic
and in practice they can be carries out easily.

Characteristics of Algorithm / Key Features of Algorithm

Algorithm has five important characteristics.


a) Finiteness: An algorithm must always terminate after a fixed number of steps. It
should not run endlessly. It should end with a solution.
b) Definiteness: Each step of the algorithm should clearly define. All the steps of
algorithm should be defined without ambiguity. All the steps of
algorithm should easy to interpret/understand.
c) Effectiveness: An algorithm must be developed by using very basic, simple, and
feasible operations so that anyone can trace it using paper and pencil.
All the operations should be performed exactly in fixed time.
d) Input: An algorithm should have zero or more inputs. An algorithm processes
this input to produce output. All the inputs must gather before
execution of the algorithm begins.
e) Output: An algorithm has one or more outputs. After perform operations
on input, an output will be generated.
f) Clear and Unambiguous:
The algorithm should be unambiguous. Each of its steps should be clear in all
aspects and must lead to only one meaning.
g) Well-Defined Inputs:
If an algorithm says to take inputs, it should be well-defined inputs. It may or
may not take input.
h) Well-Defined Outputs:
The algorithm must clearly define what output will be yielded and it should be
well-defined as well. It should produce at least 1 output.

Properties of Algorithm:
• It should terminate after a finite time.
• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same output for the same input case.
• Every step in the algorithm must be effective i.e. every step should do some work.
Advantages of Algorithms:
• It is easy to understand.
• An algorithm is a step-wise representation of a solution to a given problem.
• In an Algorithm the problem is broken down into smaller pieces or steps hence, it is easier
for the programmer to convert it into an actual program.
Disadvantages of Algorithms:
• Writing an algorithm takes a long time so it is time-consuming.

Page 3
STRUCTURED PROGRAMMING USING C UNIT - I

• Understanding complex logic through algorithms can be very difficult.


• Branching and Looping statements are difficult to show in Algorithms(imp).

How to choose best solution (algorithm)

It may be possible to solve a problem in a more than one way, resulting in more than one algorithm
The choice of various algorithms depends on the factors like
[Link]: A reliable algorithm provides the same output every time it is given the same input,
assuming the execution environment remains consistent.
[Link]: It must produce results that are correct and precise
[Link] to modify: Its design is clear, logical, and structured in a way that allows for straightforward
additions, edits, or deletions of steps without causing major disruptions
The most important factor in the choice of algorithm is the time requirement to execute / run it
(Time complexity)
Note: The algorithm which will need the least time when executed, after writing code in a high-
level language with the help of a computer is considered the best

Examples of Algorithm

Pseudocode:

Example 1:
Write an algorithm that calculates the sum and average of three numbers.
Step 1: Start
Step 2: Input a, b and c values.
Step 3: Calculate sum= a+b+c
Step 4: Calculate avg = (float)sum/3
Step 5: Write sum
Step 6: Write avg
Step 7: stop.

Example 2:
Write an algorithm to convert temperature from Fahrenheit to Celsius.
Step 1: Start
Step 2: Input F value.
Step 3: Calculate C=(F-32)*5/9
Step 4: Write C
Step 5: stop.

Page 4
STRUCTURED PROGRAMMING USING C UNIT - I

Example 3: Write an algorithm which swaps two numbers/ interchange two numbers.
Using Temporary Variable Without using temporary Using bitwise operators
variable
Step 1: Start Step 1: Start Step 1: Start
Step 2: Input a, b values Step 2: Input a, b values Step 2: Input a, b values
Step 3: Calculate t=a Step 3: Calculate a=a+b Step 3: Calculate a=a^b
Step 4: Calculate a=b Step 4: Calculate b=a-b Step 4: Calculate b=a^b
Step 5: Calculate b=t Step 5: Calculate a=a-b Step 5: Calculate a=a^b
Step 6: Write a Step 6: Write a Step 6: Write a
Step 7: Write b Step 7: Write b Step 7: Write b
Step 8: Stop Step 8: Stop Step 8: Stop
Example 4:
Algorithm to find area of triangle using heron’s formula.
Sept 1:- Start
Sept 2:- Input 3 sides (a, b, c) values
Sept 3:- Calculate s= (a+b+c)/2
Sept 4:- Calculate area=sqrt( s*(s-a)*(s-b)*(s-c))
Sept 5:- Write area
Step 6:- Stop
Example 5:
Algorithm to find distance travelled by an object.
Sept 1:- Start
Sept 2:- Input (Acceleration value) a
Sept 3:- Input (Initial velocity) u
Sept 4:- Input (Time taken) t
Sept 5:- Calc d=u*t+((float)1/2)*a*(t*t)
Step 6:- Write d
Step 7:- Stop
Example 6:
Algorithm to find net salary of an employee:
Sept 1:- Start
Sept 2:- Input basic, hra, da, pf values
Sept 3:- Calculate net_salary=basic+hra+da-pf
Sept 4:- Write net_salary
Sept 5:- stop
Example 7:
Algorithm to take 3 sides of a triangle. Print whether triangle can be drawn or not.
Sept 1:- Start
Sept 2:- Write “Enter length of 3 sides of triangle”
Sept 3:- Input A,B,C
Sept 4:- if A+B>C && B+C>A && C+A>B then
Write “Triangle Can be drawn”,
goto step5.
else
Write “Triangle cannot be drawn”.
Step 5:- stop
Example 8:
Write an algorithm which finds the biggest number among three numbers.
Step 1: Start
Page 5
STRUCTURED PROGRAMMING USING C UNIT - I

Step 2: Input a, b, c values


Step 3: If a> b && a>c then
Write “A is big”
else if b>c then
Write “B is big”
else
Write “ c is big “
Step 4: Stop
Example 9:
Write an algorithm which checks whether a no is odd number or even number.
Step 1: Start
Step 2: Input no
Step 3: If no%2=0 then
Write “Even number”
else
Write “Odd number”
Step 4: Stop
Example 10:
Write an algorithm to take percentage of marks. Print the grade.
Step 1: Start
Step 2: write “enter percentage of marks”
Step 3: input p
Step 4: if p>=75 then
Write “Distinction”
else if p>=60 then
Write “First Class”
else if p>=50 then
Write “Second Class”
else
Write “Third Class”.
Step 5: stop.

Page 6
STRUCTURED PROGRAMMING USING C UNIT - I

Flowchart
Definition : A flow chart is a step by step diagrammatic representation od the logical paths to solve
a given problem
OR
It is a visual (or) graphical representation of an algorithm.

Advantages of Flowcharts

❖ Flowchart is a picture, it explains how data is read, compute and display result.
❖ Flowchart uses symbols, shapes and arrow.
❖ The symbols form a diagram that represents an algorithm.
❖ This is very helpful in understanding complicated programs.
❖ Flowchart is used before writing actual program.
❖ Flowchart should be clear, neat and easy to follow.

Symbols used in Flowchart

Standard Symbols used in Flow-Charts:

a. Oval: Rectangle with rounded sides is used to indicate either START/ STOP of the program.

b. Input and output indicators: Parallelograms are used to represent input and output operations.
Statements like INPUT, READ and PRINT are represented in these Parallelograms.

c. Process Indicators: - Rectangle is used to indicate any set of processing operation such as for
storing arithmetic operations.

d. Decision Makers: The diamond is used for indicating the step of decision making and therefore
known as decision box. Decision boxes are used to test the conditions or ask questions and
depending upon the answers, the appropriate actions are taken by the computer. The decision box
symbol is

Page 7
STRUCTURED PROGRAMMING USING C UNIT - I

e. Flow Lines: Flow lines indicate the direction being followed in the flowchart. In a Flowchart,
every line must have an arrow on it to indicate the direction. The arrows may be in any direction

f. On- Page connectors: Circles are used to join the different parts of a flowchart and these circles
are called on-page connectors. The uses of these connectors give a neat shape to the flowcharts. Ina
complicated problems, a flowchart may run in to several pages. The parts of the flowchart on
different pages are to be joined with each other. The parts to be joined are indicated by the circle.

g. Off-page connectors: This connector represents a break in the path of flowchart which is too
large to fit on a single page. It is similar to on-page connector. The connector symbol marks where
the algorithm ends on the first page and where it continues on the second.

Flowgorithm specific symbols:

Symbol Name Purpose


Comment The Comment symbol adds documentation to the
flowchart for the readers. Comments are ignored
during the flowchart execution.
Breakpoint The Breakpoint symbol is used to pause the
flowchart execution temporarily. This symbol is
used while debugging the flowchart.
Input The Input Symbol is used to read one input from
key board. It stores input in a variable.

Page 8
STRUCTURED PROGRAMMING USING C UNIT - I

Output The Output Symbol is used to display the data on


screen.

Declare The Declare symbol is used to declare variables.

Assign/process/ The Assign symbol is used to assign / store value to


Action variable.

If The If symbol is used to makes a decision and


controls the flow. The program control takes one
branch if the condition is True. The program
control takes another branch if the condition
is False.
Call The Call symbol is used to invokes a procedure or
function. It transfers control from calling function
to called function.
While The while symbol is used to execute loop
repeatedly.
For The for symbol is used to execute loop repeatedly.

Do The Do symbol is used to execute loop repeatedly.


Do loop executes the loop at least once.

Why flow charts?

To simplify complex Processes by breaking them into easy-to-understand visual steps which
improves communication, aids in decision making, facilitates problem solving and process
improvement, and provides clear documentation for processes, algorithms and workflow across
various fields .

Purpose of Flowchart

❖ Flowchart is used to convert algorithm into picture.


❖ Flowchart tells how an algorithm works.
❖ Flowchart tells how a process works.
❖ Flowchart helps to understand a process easily.
❖ Flowchart helps to identify mistakes.
❖ Flowchart helps to identify redundancies.
❖ Flowchart is useful during the planning phase of software development.
❖ Flowchart helps to break down a complex problem into smaller, manageable parts.
❖ Flowchart makes easier to explain the process to others

Page 9
STRUCTURED PROGRAMMING USING C UNIT - I

Examples

Example 1: Draw flowchart to print sum of two numbers:

Example 2: Draw the flowchart that calculates the simple interest.

Example 3: Draw the flowchart to swap two numbers.

Page 10
STRUCTURED PROGRAMMING USING C UNIT - I

Example 4: Draw the flowchart which finds the biggest number among two numbers.

Example 5: draw the flowchart to find big no from 3 nos.


Page 11
STRUCTURED PROGRAMMING USING C UNIT - I

Page 12
STRUCTURED PROGRAMMING USING C UNIT - I

Example 6: Draw the flow chart which finds the factorial of given numbers.

Practice Sheet 1
Example 1: Draw a flowchart to print following rhyme
Twinkle, twinkle, little star,
how I wonder what you are.
Up above the world so high,
like a diamond in the sky.

Example 2: Draw a flowchart to print following rhyme


Ring o ring o roses,
A pocketful of posies,
A-tishool A-tishool,
We all fall down
Example 3: Draw a flowchart to find net salary of an employee using formula
Net = basic + hra + da - pf
Example 4: Draw a flowchart to convert a lower case character to upper case character
using ch=ch-32 .
Example 5: Draw a flowchart to find M value using M=(a+b+c+d+e)/5
Example 6: Draw a flowchart to find result of add 3 to the quantity 4 times 5
Example 7: Draw a flowchart to find y value using y=ax2+bx+c
Example 8: Draw a flowchart to convert seconds into hours and minutes
Example 9: Draw a flowchart to convert hours and minutes into Seconds
Page 13
STRUCTURED PROGRAMMING USING C UNIT - I

Example 10: Draw a flowchart to find y value using y=ax3-bx2-6


Example 11: Draw a flowchart to find y value using y=2x1-3x2+5x3+4
Example 12: Draw a flowchart to convert distance from miles to kilometers using
km=1.609*miles
Example 13: Draw a flowchart to find distance travelled by object using
S=ut+1/2at2

History of C language

❖ In the early 1960s, computer scientists worked with low-level languages, which were hard to
write and maintain.
❖ To make programming easier, higher-level languages like ALGOL were created in 1960, but
they were still not perfect for system software.
❖ In 1966, Martin Richards developed BCPL (Basic Combined Programming Language),
mainly used for writing compilers and system software.
❖ In 1969, Ken Thompson improved BCPL to B, B is mainly used to develop UNIX operating
system.
❖ C was developed to overcome the limitations of languages like B and BCPL
❖ C is a general-purpose programming language that was originally created by Dennis Ritchie in
1972 in Bell Laboratories of AT&T Labs. It was originally intended as a system programming
language to implement the UNIX system.
❖ Dennis Ritchie began programming in C in 1972, as an effort to make UNIX
❖ By 1973, the UNIX operating system was virtually rewritten in C
❖ C is more powerful and flexible for system programming.

Variations in C:

ANSI C (C89/C90): In 1983 the American National Standards Institute (ANSI) committee
completed a final draft standard known as ANSI C

ANSI C standard was approved by International Organization for Standardization (ISO) as (C90).

C99 (1999): C99 introduced a variety of constructs, including: inline functions, variable-length
arrays, complex numbers, and other improvements to floating-point operations. C99 also introduced
the long long data type and the nature of single-line comments (//).

C11 (2011): C11 introduced many new features and addressed safety and concurrency.

C17/C18 (2017): The C17/C18 standard is a minor revision of C11


Page 14
STRUCTURED PROGRAMMING USING C UNIT - I

C23 (2023): C23 is the latest standard, which added features such as nullptr, binary literals

Example : binary_value_1 = 0b1010; binary_value_2 = 0B1111

Compiler vs Interpreter

A translator is used to bridge the gap between human-readable source code and machine executable
code, as computer can’t understand the human languages

Compiler:
Compilers translate the entire program into machine readable code before execution,
resulting faster, standalone programs
.

1. High Performance

Compiler translate the entire source code into machine code or byte code once, which allows the
resulting program to run much faster because its closer to the hardware

2. Standalone executable

It produces an executable file that can run on its own without needing the original source code

C Compilers:

• GCC (GNU Compiler Collection):


1. This is a free and open-source compiler suite that supports C, C++, Objective-C,
2. It is the default compiler on most Unix-like systems, including Linux and macOS.
• Microsoft Visual C++ (MSVC):
1. This is Microsoft's proprietary C and C++ compiler, bundled with Visual Studio.

Interpreter:

Interpreters translate and execute the code line -by-line during the runtimr,offers portability and
quick debugging of errors

[Link]:
Page 15
STRUCTURED PROGRAMMING USING C UNIT - I

Interpreted Programs are generally platform independent the same code can run on different
platforms as long as an interpreter is available

[Link] of debugging:

These identify errors line by line, allowing for easier and quicker debugging compared to compiler

Difference between Compiler and Interpreter:

Compiler Interpreter
Compiler is software which translate entire Interpreter is software which translate source
source code into machine code at once. code into machine code line by line.
Generate executable file .exe Does not generate executable file
Program executes faster program executes slowly
It shows all the errors at once. It shows errors one by one
Use more memory. Use less memory.
Examples: C, C++, JAVA Examples : python, Java Script
Recompilation is required when we do the Recompilation is not required when we do the
modifications to program,. modifications to program.
Source code does not require for later execution. Source code is required for later execution.
CPU utilization is more CPU utilization is low

Features of C

Key Features of C are


1. Middle Level Language :- C is a middle-level language because it supports features of low-
level language and high-level languages.
2. Case sensitive language:- C is called a case-sensitive language because it distinguishes
between uppercase and lowercase. For example, variable, VARIABLE,
and Variable would be treated as three distinct entities in C.
3. Structured programming language:- C is a structured programming language because it
supports modular programming by allowing code to be broken into functions, improving
clarity and reuse.
4. Procedure-Oriented Programming Language:- C is a procedure-oriented programming
language because it allows step-by-step approach to problem-solving, breaking down tasks
into smaller, manageable procedures or functions.
5. Platform Dependent Language:- C is a platform-dependent language because its compiled
code (machine code) depends on operating system and hardware. This means a C program
compiled for one platform (e.g., Windows) won't directly run on another platform (e.g.,
Linux) without recompilation.
6. Simple Programming Language: - C is simple programming language due to its straight
forward syntax, and the direct relationship between its code and machine instructions.
7. Typed Programming Language :- C is a typed programming language because every
variable and expression associated with data type. Compiler can understand the data type of
Page 16
STRUCTURED PROGRAMMING USING C UNIT - I

variable or expression at the time of compilation.


8. Portable Language :- C is a portable language because its source code can be compiled and
run on different computer systems having same platform without any modification.
9. General Purpose Language :- C is a general-purpose programming language because it can
be used to develop a wide range of applications like operating systems, embedded systems,
game development, scientific computing.
10. Extensible Language : C is a extensible language because a user can add new features and
functions to existing C library.

Applications of C

Application of C Description and Examples

Operating System C is used to develop operating systems like UNIX and Linux, enabling
Development efficient management of hardware and system resources.

Embedded Systems and C powers embedded systems in devices such as automotive controllers
IoT Devices and smart home gadgets, ensuring real-time performance and precise
hardware control.

Compilers and Many compilers are written in C, facilitating the translation of high-
Interpreters level code into machine-executable instructions.

Database Systems High-performance databases like MySQL and Oracle utilize C for
efficient data management, query processing, and transaction handling.

Game Development and C is used in developing game engines for titles like Doom and Quake,
Graphics enabling high-performance graphics rendering and real-time processing.

Network Programming C is employed to implement network protocols and develop device


and Drivers drivers, ensuring efficient data transmission and seamless hardware
interactions.

System Utilities and Essential utilities such as grep and the GNU Core Utilities are built with
Command-Line Tools C, providing fast and powerful system-level functionalities.

High-Performance C is pivotal in high-performance computing (HPC) applications and


Computing and Scientific scientific research tools like LAPACK and GNU Scientific Library
Research (GSL), enabling rapid computations and large-scale simulations

Structure of C Program

A “C‟ program is a group of building blocks called functions. A function is a subroutine that
may include one or more statements designed to perform a specific task. To write a C
program we first create functions and then put them together. Any C program may contain
one or more sections as shown in the figure.

Page 17
STRUCTURED PROGRAMMING USING C UNIT - I

Documentation Section //optional


Link Section//optional/mandatory
Definition Section //optional
Global declaration Section //optional
main( ) function section //mandatory
{
Declaration part
Executable part
}
Subprogram Section //optional
Function -1
Function-2

Function-n

Documentation Section:
To enhance the readability of the program, programmers can provide comments about the
program in this section. The comments are included between the delimiters /* and */.
Example:
/*Write a program to find sum of 2 numbers */
These statements are not executable rather they are ignored by the compiler. Comments can
be used anywhere in the program.

Link Section:
This section instructs the compiler to link functions from the “C‟ library. Library functions
are grouped category wise and stored in different files known as header files. If we want to
access the functions stored in the library, it is necessary to tell the compiler about the files to
be accessed. This can be done through a preprocessor directive #include <filename>

Ex: #include<stdio.h>
This statement instructs the compiler to copy the content of “stdio.h” into our program
before starting the compiling step.

Definition Section:
It is used to define symbolic constants and to define macros. The preprocessor directive
#define is used for the purpose.

Ex: #define PI 3.14


This statement creates a constant and named it as PI and its value is 3.14.
Global Declaration Section:
There are two places where variables and functions are declared inside a function or declared
outside the function. Variables declared outside the functions are called global variables.
Example :
int no; // global variable
void main()
{
int no2=20; // local variable
}
Page 18
STRUCTURED PROGRAMMING USING C UNIT - I

No2=no1+10
Main( ) Function Section:
The main( ) is a special function used by the C system to tell the computer where the program
starts. Every program must have exactly one main function. This section has two parts
a) Declaration part
b) Execution part

The declaration part declares all the variables that are used in the executable part. There
is at least one statement in the executable part. These two parts can appear between the
opening and closing braces. In all C programs execution begins at this opening brace and
ends at this closing brace. The closing brace of this function is the logical end of the program.
All the declaration and executable statements end with a semicolon.
Example :
void main()
{
Declaration part
Execution part
}

Subprogram Section:
This section contains user defined functions that are used in the main function. User defined
functions are generally placed immediately after the main function.

All Sections except the main function section may be absent when they are not required.

Example Program:
/* A Sample C program */ /* documentation section*/
#include <stdio.h> /* Link section*/
#define PI 3.14 /* Definition section*/
int area; /*global variables declaration part*/
/*main( ) function section begins*/
main( )
{
int radius; /*local variables declaration part*/
printf(“Enter radius : “);
scanf(“%d”, &radius);
find_area(radius);
printf(“area of the circle = %d”,area);
}
/* main() function section ends*/
/* sub function section begins*/
void find_area(int radius)
{
area=PI*radius*radius;
}
/* sub function section ends*/

Page 19
STRUCTURED PROGRAMMING USING C UNIT - I

Tokens of C Language

Tokens in C are the most important elements to be used in creating a program in C. We can define
the token as the smallest individual element in C. For `example, we cannot create a sentence without
using words; similarly, we cannot create a program in C without using tokens. Therefore, we can say
that tokens in C are basic components for creating a program.

1. Identifiers :-
Identifiers are the names allocated to variables or methods or functions or user defined
references like arrays, structures, unions, enums and constants. Identifiers names should
be unique. Identifiers names should be meaningful. These consist of a sequence of letters,
digits and underscore. Both uppercase and lowercase letters are permitted but commonly use
lower case letters. Name of identifier is Case Sensitive. Identifiers cannot be used as
keywords. Identifiers should be written in such a way that it is meaningful, short, and easy to
read.
Examples 1:
int a;
char ch;
Here “a” and “ch” are identifiers of variables

Example 2:
void main()
{
//code
}
Here main is identifier of function.
Example 3:
struct Student
{
int no;
char sname[100];
};
Here Student is identifier of structure.
Example 4:
#define PI 3.14

Page 20
STRUCTURED PROGRAMMING USING C UNIT - I

Here PI is identifier of constant.

The following rules need to be followed while naming identifiers.


1. Name of Identifier consists alphabets, digits or underscore.
2. Name of Identifier must begin with an alphabet or underscore.
3. Name of Identifier does not allow space.
4. Name of Identifier does not allow any special character except underscore.
5. Name of Identifier should not be Keyword.
6. Length of Name of Identifier should not exceed 32 characters.

Valid Invalid Identifiers Reason for not valid


identifiers
No1 1no Identifier should not begin with digit.
no1 Odd numbers sum Identifier should not have space.
Odd_sum Odd-sum Identifier does not allow any special character
int, char, float, Identifier should not be a keyword
Abcdef…. z012…9 Length of identifier should not exceed 32 characters

2. Keywords: -
Keywords are the pre-defined identifiers. Keywords are the system defined identifiers.
Keywords are the reserved words. Keywords are words that have special meaning. We
should not change the meaning of keywords. If we try the change its meaning then we will
get error. Keywords are part of the syntax. These cannot be used as an identifier. All
keywords must be written in lowercase. C language provides 32 keywords.
Examples
auto double int struct
break else long switch
case enum register typedef
char extern return union
Const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

3. Constants / Literals
Constant is a container that retains its value until program termination. The value of constant
cannot be changed. If we try to change the value of constant then we will get an error. “C‟
supports several types of constants as shown in the figure. Constant name should be
represented in upper case.

Page 21
STRUCTURED PROGRAMMING USING C UNIT - I

Integer Constants: An integer constant is a sequence of digits without a decimal point. No


commas, no blank spaces are allowed. It could be either positive or negative. If no sign
proceeds it is assumed to be positive. It may be specified in decimal, octal or hexadecimal
notation.
Decimal Integer Constant: It consists of sequence of one or more decimal digits from 0 to 9. It
can be preceded by an optional – or + sign.
Ex: 0 , -321 , 3412
Octal Integer Constant: It consists of the digit 0 followed by a sequence of one or more octal
digits from 0 to 7.
Ex: 012 , 07134
Hexadecimal Integer Constant: It consists of the digit 0, followed by one of the letter x or X ,
followed by a sequence of one or more hexadecimal digits from 0 to 9 or letter from A to F or a
to f.
Ex: 0x2 0X9F, 0xbcd
The largest integer value that can be stored is machine dependent.

Real Constants: A Real constant or floating point constant is a sequence of digits with a
decimal point. No commas, no blank spaces are allowed. It could be either positive or negative.
If no sign proceeds it is assumed to be positive.
Ex: valid floating-point constants 0.00083 , -0.35 , 435.98 , 95
A real constant may also be expressed in exponential (or scientific) notation. The scientific
notation is often used to express numbers that are very small or very large. For ex, that
0.000000011 is written as 1.1 × 10-8. The general form is
Mantissa e exponent
The mantissa is either a real number expressed in decimal notation or an integer. The exponent
is an integer number with an optional + or – sign.
Ex: valid floating-point constants: 0.65e4 , 12e-2, 1.5E+5
Invalid floating point constants:
6,700.25 commas is not permitted
5e+2.5 exponents must be an integer
Floating point constants are normally represented as double precision quantities. However, the
suffixes f or F may be used to force single precision and l or L to extend double precision.
Character Constants: Any single character enclosed with in pair of single quotation marks is
called a character constant.
Ex: ‘5’, ‘x’, ‘ ‘
The last constant is a blank space. The character constant ‘5’ is not the same as 5.
Character Constants have integer values known as ASCII values. Since each character
constant represent an integer value it is also possible to perform arithmetic operations on
character constants.
String Constant: A String Constant is a sequence of characters enclosed in double quotes. The
characters may be letters, numbers, special characters and blank space.
Ex: “VVIT”, “P”, “5+3”,
The character constant (ex: ‘p’) is not equivalent to the string constant (ex: “p”). A string
constant does not have an associated ASCII value, whereas character constant has an integer
value.

4. Special Characters :

Some special characters are used in C, and they have a special meaning which cannot be used
for another purpose.

Page 22
STRUCTURED PROGRAMMING USING C UNIT - I

o Square brackets [ ]: The opening and closing brackets represent the single and
multidimensional subscripts.
o Simple brackets ( ): It is used in function declaration and function calling. For example,
printf() is a pre-defined function.
o Curly braces { }: It is used in the opening and closing of the code. It is used in the opening
and closing of the loops.
o Comma (,): It is used for separating for more than one statement and for example, separating
function parameters in a function call, separating the variable when printing the value of
more than one variable using a single printf statement.
o Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we
are using the header file.
o Asterisk (*): This symbol is used to represent pointers and also used as an operator for
multiplication.
o Tilde (~): It is used as a destructor to free memory.
o Period (.): It is used to access a member of a structure or a union.

5. Strings :- Strings are nothing but an array of characters ended with a null character (‘\0’). This
null character indicates the end of the string. Strings are always enclosed in double quotes.

Example : char str[ ] = "Hello, World!";

6. Operators:- Operator is a tool / symbol which is used to perform operations. Operators


are used to manipulate data and variables. The variables and constants can be combined
together by various operators to form expressions. The operators perform operations to
generate output.

Example : +, -, *, /, %, =, ==, !=, >, <, >=, <=, &&, ||, ++, -- etc..

Formatted IO Functions / Formatted Input & Output Functions

• These functions are used to control how data is read from input devices and written to
output devices
• These functions use format specifiers to define the datatype and representation of input
and output
• The primary formatted I/O functions are
o Printf()
o Scanf ()

Usually the input is given & output is viewed on the screen with the help of input & output
functions in C. The standard or regularly used I/O functions are:
printf () :–
------------------------------
• It stands for print formatted.
• It is a formatted output function.
• It sends a formatted string to output devices.
• It is used to print output on screen. It is a general purpose output function.
• It can print any type of data.
• It can print multiple values at a time.
• It executes from right side to left side. It was defined in “stdio.h”.
• It returns how many bytes of information get printed successfully on screen.
Page 23
STRUCTURED PROGRAMMING USING C UNIT - I

Syntax :

int printf(“Format Specifiers / formatted string”,variable1,variable2…);

Here formatted string contains the text to be displayed on screen. The general form of formatted
string is “%[flag][width][.precision][length]specifier”.

Explanation :
printf(“% - 10.2lf”,salary);
Here
“-“ is called flag
10 is width
2 is precision
“l” is length
“f” is specifir

Example : Write a C program to print following rhyme


Row, row, row your boat
Gently down the stream
Merrily, merrily, merrily, merrily
Life is but a dream
#include <stdio.h>
void main()
{
printf("Row, row, row your boat\n");
printf("Gently down the stream\n");
printf("Merrily, merrily, merrily, merrily\n");
printf("Life is but a dream\n");
}
scanf():-
-----------------------------------
It stands for scan formatted.
It is used for input.
It reads input from keyboard.
It can read any type of data.
It can read multiple values at a time. It was defined in “stdio.h”.
It execute from left side to right side. It returns how many items successfully read.
Syntax:

scanf(“format specifiers / formatted string”, &variable1, &variable2,..);

here “&” symbol gives the address of variable.


Example: Write a C program to convert hours and minutes into Seconds
#include <stdio.h>
void main()
{
int hours, minutes, total_seconds;
printf("Enter hours: ");
scanf("%d", &hours);
printf("Enter minutes: ");
scanf("%d", &minutes);

Page 24
STRUCTURED PROGRAMMING USING C UNIT - I

total_seconds = (hours * 3600) + (minutes * 60);


printf("Total time in seconds: %d", total_seconds);
}
The above two input & output functions are also known as formatted I/O functions.

Unformatted Input Functions:


These functions read data from the standard input (keyboard), typically character by character or as a
string, without requiring format specifiers.

• getchar(): Reads a single character from the standard input and returns its integer value
(ASCII value). It requires the Enter key to be pressed.

char ch = getchar();
• getch(): Reads a single character from the keyboard without echoing it to the screen and
without requiring the Enter key. (Requires conio.h).

char ch = getch();

• gets(): Reads a string from the standard input until a newline character is encountered.

char str[100];
gets(str);

Unformatted Output Functions:

These functions display data to the standard output (console) without specific formatting.

• putchar(): Displays a single character to the standard output.

char ch = 'A';
putchar(ch);
• putch(): Displays a single character to the console. (Requires conio.h).

char ch = 'B';
putch(ch);
• puts(): Displays a string to the standard output, automatically adding a newline character at
the end.
char str[] = "Hello, World!";
puts(str);

Key Differences from Formatted I/O:


1. No Format Specifiers: Unformatted functions do not use format specifiers like %d, %f,
or %s.
2. Data Type Restriction: They are primarily designed for character and string data.

Page 25
STRUCTURED PROGRAMMING USING C UNIT - I

Format Specifiers:

That tell a program how to format and display data in input/output functions

Data Type / Use Format


Meaning / Example Example Code
Case Specifier
Integer %d or %i Signed decimal integer printf("%d", 25);
short int %hd Signed short integer short x=12; printf("%hd",x);
Unsigned decimal
unsigned int %u unsigned int y=50; printf("%u",y);
integer
long int %ld Signed long integer long a=123456; printf("%ld",a);
unsigned long b=123456;
unsigned long int %lu Unsigned long integer
printf("%lu",b);
Signed long long long long c=9876543210;
long long int %lld
integer printf("%lld",c);
unsigned long long Unsigned long long unsigned long long d=9876543210;
%llu
int integer printf("%llu",d);
Character %c Single character char ch='A'; printf("%c",ch);
String %s Null-terminated string char str[]="Hello"; printf("%s",str);
Float %f Decimal floating point float f=12.345; printf("%f",f);
Double %lf Double precision float double d=45.6789; printf("%lf",d);
Extended precision long double ld=23.456789;
Long Double %Lf
float printf("%Lf",ld);
Boolean (_Bool /
%d 0 (false) or 1 (true) bool flag=true; printf("%d",flag);
bool)
Pointer %p Memory address int x; printf("%p",&x);
Octal %o Octal representation printf("%o",255); → 377
Hexadecimal
%x Hexadecimal lowercase printf("%x",255); → ff
(lowercase)
Hexadecimal
%X Hexadecimal uppercase printf("%X",255); → FF
(uppercase)
Width & Precision
%10.3f Width=10, precision=3 printf("%10.3f",12.3456); → " 12.346"
(float)
Width=10, precision=3, printf("%-10.3f",12.3456); → "12.346
Left align %-10.3f
left align “

C language provides some tools using which we can format the input and output. They are generally
inserted between the % sign and the format specifier symbol Some of them are as follows:
1. A minus(-) sign tells left alignment.
2. A number after % specifies the minimum field width to be printed if the characters are less
than the size of the width the remaining space is filled with space and if it is greater then it is
printed as it is without truncation.
3. A period( . ) symbol separates field width with precision.

Example :
Page 26
STRUCTURED PROGRAMMING USING C UNIT - I

#include <stdio.h>
int main()
{
char str[] = "Welcome";
printf("%20s\n", str);
printf("%-20s\n", str);
printf("%20.5s\n", str);
printf("%-20.5s\n", str);
return 0;
}

Output :
Welcome
Welcome
Welco
Welco

Escape Sequences:
Escape sequences are special character combinations, beginning with a backslash (\), that represent
characters or actions not easily typed directly, such as a new line (\n) or a double quote (\")

Escape
Meaning Example Code Output
Sequence
Hello
\n Newline printf("Hello\nWorld");
World
\t Horizontal tab printf("A\tB"); A B
\\ Backslash printf("\\"); \
\" Double quote printf("\"Hello\""); "Hello"
\' Single quote printf("\'A\'"); 'A'
\a Alert (bell) printf("\a"); Beep sound
\b Backspace printf("ABC\bD"); ABD
\f Form feed printf("Hello\fWorld"); Page break effect
\r Carriage return printf("Hello\rWorld"); World
Hello (vertical tab)
\v Vertical tab printf("Hello\vWorld");
World
\0 Null character (string terminator) printf("Hi\0World"); Hi
\ooo Octal value (ooo = octal digits) printf("\101"); A
Hexadecimal value (hh = hex
\xhh printf("\x41"); A
digits)

Page 27
STRUCTURED PROGRAMMING USING C UNIT - I

ASCII TABLE :
ASCII (American Standard Code for Information Interchange) is a 7-bit character encoding
standard with 128 values (0–127) representing letters, digits, symbols, and control codes.
Dec Hex Char Description Binary
0 00 NUL Null character 00000000
1 01 SOH Start of Header 00000001
2 02 STX Start of Text 00000010
3 03 ETX End of Text 00000011
4 04 EOT End of Transmission 00000100
5 05 ENQ Enquiry 00000101
6 06 ACK Acknowledge 00000110
7 07 BEL Bell 00000111
8 08 BS Backspace 00001000
9 09 TAB Horizontal Tab 00001001
10 0A LF Line Feed (newline) 00001010
11 0B VT Vertical Tab 00001011
12 0C FF Form Feed 00001100
13 0D CR Carriage Return 00001101
14 0E SO Shift Out 00001110
15 0F SI Shift In 00001111
16 10 DLE Data Link Escape 00010000
17 11 DC1 Device Control 1 00010001
18 12 DC2 Device Control 2 00010010
19 13 DC3 Device Control 3 00010011
20 14 DC4 Device Control 4 00010100
21 15 NAK Negative Acknowledge 00010101
22 16 SYN Synchronous Idle 00010110
End of Transmission
23 17 ETB 00010111
Block
24 18 CAN Cancel 00011000
25 19 EM End of Medium 00011001
26 1A SUB Substitute 00011010
27 1B ESC Escape 00011011
28 1C FS File Separator 00011100
29 1D GS Group Separator 00011101
30 1E RS Record Separator 00011110
31 1F US Unit Separator 00011111
32 20 SPACE Space 00100000
33 21 ! Exclamation mark 00100001
34 22 " Double quote 00100010

Page 28
STRUCTURED PROGRAMMING USING C UNIT - I

Dec Hex Char Description Binary


35 23 # Hash 00100011
36 24 $ Dollar 00100100
37 25 % Percent 00100101
38 26 & Ampersand 00100110
39 27 ' Single quote 00100111
40 28 ( Left parenthesis 00101000
41 29 ) Right parenthesis 00101001
42 2A * Asterisk 00101010
43 2B + Plus 00101011
44 2C , Comma 00101100
45 2D - Hyphen 00101101
46 2E . Period 00101110
47 2F / Slash 00101111
48 30 0 Digit 0 00110000
49 31 1 Digit 1 00110001
50 32 2 Digit 2 00110010
51 33 3 Digit 3 00110011
52 34 4 Digit 4 00110100
53 35 5 Digit 5 00110101
54 36 6 Digit 6 00110110
55 37 7 Digit 7 00110111
56 38 8 Digit 8 00111000
57 39 9 Digit 9 00111001
58 3A : Colon 00111010
59 3B ; Semicolon 00111011
60 3C < Less than 00111100
61 3D = Equal 00111101
62 3E > Greater than 00111110
63 3F ? Question mark 00111111
64 40 @ At symbol 01000000
65 41 A Uppercase A 01000001
66 42 B Uppercase B 01000010
67 43 C Uppercase C 01000011
68 44 D Uppercase D 01000100
69 45 E Uppercase E 01000101
70 46 F Uppercase F 01000110
71 47 G Uppercase G 01000111
72 48 H Uppercase H 01001000

Page 29
STRUCTURED PROGRAMMING USING C UNIT - I

Dec Hex Char Description Binary


73 49 I Uppercase I 01001001
74 4A J Uppercase J 01001010
75 4B K Uppercase K 01001011
76 4C L Uppercase L 01001100
77 4D M Uppercase M 01001101
78 4E N Uppercase N 01001110
79 4F O Uppercase O 01001111
80 50 P Uppercase P 01010000
81 51 Q Uppercase Q 01010001
82 52 R Uppercase R 01010010
83 53 S Uppercase S 01010011
84 54 T Uppercase T 01010100
85 55 U Uppercase U 01010101
86 56 V Uppercase V 01010110
87 57 W Uppercase W 01010111
88 58 X Uppercase X 01011000
89 59 Y Uppercase Y 01011001
90 5A Z Uppercase Z 01011010
91 5B [ Left bracket 01011011
92 5C \ Backslash 01011100
93 5D ] Right bracket 01011101
94 5E ^ Caret 01011110
95 5F _ Underscore 01011111
96 60 ` Backtick 01100000
97 61 a Lowercase a 01100001
98 62 b Lowercase b 01100010
99 63 c Lowercase c 01100011
100 64 d Lowercase d 01100100
101 65 e Lowercase e 01100101
102 66 f Lowercase f 01100110
103 67 g Lowercase g 01100111
104 68 h Lowercase h 01101000
105 69 i Lowercase i 01101001
106 6A j Lowercase j 01101010
107 6B k Lowercase k 01101011
108 6C l Lowercase l 01101100
109 6D m Lowercase m 01101101
110 6E n Lowercase n 01101110

Page 30
STRUCTURED PROGRAMMING USING C UNIT - I

Dec Hex Char Description Binary


111 6F o Lowercase o 01101111
112 70 p Lowercase p 01110000
113 71 q Lowercase q 01110001
114 72 r Lowercase r 01110010
115 73 s Lowercase s 01110011
116 74 t Lowercase t 01110100
117 75 u Lowercase u 01110101
118 76 v Lowercase v 01110110
119 77 w Lowercase w 01110111
120 78 x Lowercase x 01111000
121 79 y Lowercase y 01111001
122 7A z Lowercase z 01111010
123 7B { Left brace 01111011
124 7C | Vertical bar 01111100
125 7D } Right brace 01111101
126 7E ~ Tilde 01111110
127 7F DEL Delete 01111111

Number System :

Number system conversion is a fundamental concept in computer science and programming. It


involves changing the representation of a number from one base to another

There are four common types of number systems based on the radix or base of the number

1. Decimal Number System


• The Decimal system is a base-10 number system.
• It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.

Page 31
STRUCTURED PROGRAMMING USING C UNIT - I

• Each digit’s place value is a power of 10 (e.g., 100, 101, 102).


• It is the standard system for everyday counting and calculations.
2. Binary Number System
• The Binary system is a base-2 number system.
• It uses two digits: 0 and 1.
• Each digit’s place value is a power of 2 (e.g., 20, 21, 22).
• The Binary system is the foundation for data representation in computers and digital
electronics.
3. Octal Number System
• The Octal system is a base-8 number system.
• It uses eight digits: 0, 1, 2, 3, 4, 5, 6 and 7.
• Each digit’s place value is a power of 8 (e.g., 80, 81, 82).
• It is often used to simplify the representation of binary numbers by grouping them into sets
of three bits.
4. Hexadecimal Number System
• The Hexadecimal system is a base-16 number system.
• It uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F (where A = 10, B = 11,
etc.).
• Each digit’s place value is a power of 16 (e.g., 160, 161, 162).
• Hexadecimal simplifies binary by representing every 4 bits as one digit (0-F).

Number System Conversion Methods


A number N in base or radix b can be written as:
(N)b = dn-1 dn-2 -- -- -- -- d1 d0 . d-1 d-2 -- -- -- -- d-m
In the above, dn-1 to d0 is the integer part, then follows a radix point and then d-1 to d-m is the
fractional part.

dn-1 = Most significant bit (MSB)


d-m = Least significant bit (LSB)

1. Decimal to Binary Number System Conversion


For Integer Part:
• Divide the decimal number by 2.
• Record the remainder (0 or 1).
• Continue dividing the quotient by 2 until the quotient is 0.
• The binary equivalent is the remainders read from bottom to top.
For Fractional Part:
• Multiply the fractional part by 2.
• Record the integer part (0 or 1).

Page 32
STRUCTURED PROGRAMMING USING C UNIT - I

•Take the fractional part of the result and repeat the multiplication.
•Continue until the fractional part becomes 0 or reaches the desired precision.
•The binary equivalent is the integer parts recorded in sequence.
Example: (10.25)10

For Integer Part (10):


• Divide 10 by 2 → Quotient = 5, Remainder = 0
• Divide 5 by 2 → Quotient = 2, Remainder = 1
• Divide 2 by 2 → Quotient = 1, Remainder = 0
• Divide 1 by 2 → Quotient = 0, Remainder = 1
Reading the remainders from bottom to top gives 1010.
For Fractional Part (0.25):
• Multiply 0.25 by 2 → Result = 0.5, Integer part = 0
• Multiply 0.5 by 2 → Result = 1.0, Integer part = 1
The fractional part ends here as the result is now 0. Reading from top to bottom gives 01.
Thus, the binary equivalent of (10.25)10 is (1010.01)2.

2. Binary to Decimal Number System Conversion


For Integer Part:
• Write down the binary number.
• Multiply each digit by 2 raised to the power of its position, starting from 0 (rightmost digit).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the binary integer.
For Fractional Part:
• Write down the binary fraction.
• Multiply each digit by 2 raised to the negative power of its position, starting from -1 (first
digit after the decimal point).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the binary fraction.
Example: (1010.01)2
1x23 + 0x22 + 1x21+ 0x20 + 0x2 -1 + 1x2 -2 = 8+0+2+0+0+0.25 = 10.25
Thus, (1010.01)2 = (10.25)10

3. Hexadecimal to Binary Number System Conversion


To convert from Hexadecimal to Binary:
• Each hexadecimal digit (0-9 and A-F) is represented by a 4-bit binary number.
Page 33
STRUCTURED PROGRAMMING USING C UNIT - I

• For each digit in the hexadecimal number, find its corresponding 4-bit binary equivalent and
write them down sequentially.

Example: (3A)16
• (3)16 = (0011)2
• (A)16 = (1010)2
Thus, (3A)16 = (00111010)2

[Link] to Hexadecimal Number System Conversion

To convert from Binary to Hexadecimal:


• Start from the rightmost bit and divide the binary number into groups of 4 bits each.
• If the number of bits isn't a multiple of 4, pad the leftmost group with leading zeros.
• Each 4-bit binary group corresponds to a single hexadecimal digit.
• Replace each 4-bit binary group with the corresponding hexadecimal digit.
Example: (1111011011)2
0011 1101 1011
|||
3DB
Thus, (001111011011 )2 = (3DB)16

5. Binary to Octal Number System


To convert from binary to octal:
• Starting from the rightmost bit, divide the binary number into groups of 3 bits.
• If the number of bits is not a multiple of 3, add leading zeros to the leftmost group.
• Each 3-bit binary group corresponds to a single octal digit.
• The binary-to-octal conversion for each 3-bit group is as follows:
• Replace each 3-bit binary group with the corresponding octal digit.

Page 34
STRUCTURED PROGRAMMING USING C UNIT - I

Example: (111101101)2
111 101 101
|||
755
Thus, (111101101)2 = (755)8

6. Octal to Binary Number System Conversion


To convert from octal to binary:
• Each octal digit (0-7) corresponds to a 3-bit binary number.
• For each octal digit, replace it with its corresponding 3-bit binary equivalent.
Example: (153)8
• Break the octal number into digits: 1, 5, 3
• Convert each digit to binary:
o 1 in octal = 001 in binary
o 5 in octal = 101 in binary
o 3 in octal = 011 in binary
Thus, (153)8 = (001101011)2

Page 35
STRUCTURED PROGRAMMING USING C UNIT - I

Questions from previous question papers for reference purpose

1. What is the difference between compiler and interpreter?


2. What are the essential steps in the development an algorithm?
3. Define flowchart. Explain with an example?
4. Write the general structure of C?
5. What are the basic steps involved in writing a computer program?
6. Write algorithm and draw a flow chart for reversing a given number.
7. Develop a flowchart for calculating area of an equilateral triangle. Area of
equilateral triangle is computed by formula A= (_3 ⁄4) a2, where ‘a’ is length of side
of triangle?
8. Develop an algorithm to print the Fibonacci series.
9. Define algorithm? Write the characteristics of an algorithm. Give example.
10. Define keyword, constant and variable?
11. What is a programming language? Why C language is called as Middle level
12. programming language? Explain?
13. Define flowchart? How it is useful in writing the programs? Explain about different
14. symbols in Flow chart? Give Example?
15. Explain about Compiler, Interpreter, and Assembler?
16. Explain the process of Creating, Compiling and Execution of a C Program?
17. What is Constant? Explain different types of Constants available in C with examples?
18. Implement an algorithm to find the sum of all the numbers in given range of numbers.?
19. How does a control string in a printf() function differ from the control string in a scanf() function.?
Write commonly used scanf() format codes?
20. Explain the following with examples
(i) Constants and types of constants
(ii) Variables and rules for naming variables.

Page 36

You might also like