0% found this document useful (0 votes)
15 views

Research 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Research 5

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 87

Introduction To

C Programming
 C Languageis a general purpose language is developed by Dennis
Ritchie at the Bell Laboratory in 1972
Types of Language
 1 Low Level: *Assembly Language ,* Machine Language

 2 High Level : Procedure Language , Object Oriented Language


Low Level Language
Assembly Level
Language
Procedure Oriented
Object Oriented
Procedural Programming vs Object-Oriented
Programming
Below are some of the differences between procedural and
object-oriented programming:
Procedural Oriented Programming Object-Oriented Programming

In procedural programming, the program is divided into In object-oriented programming, the program is divided
small parts called functions. into small parts called objects.

Object-oriented programming follows a bottom-up


Procedural programming follows a top-down approach.
approach.

Object-oriented programming has access specifiers like


There is no access specifier in procedural programming.
private, public, protected, etc.

Adding new data and functions is not easy. Adding new data and function is easy.

Procedural programming does not have any proper way of Object-oriented programming provides data hiding so it
hiding data so it is less secure. is more secure.

In procedural programming, overloading is not possible. Overloading is possible in object-oriented programming.

In procedural programming, there is no concept of data In object-oriented programming, the concept of data hiding
hiding and inheritance. and inheritance is used.

In procedural programming, the function is more important In object-oriented programming, data is more important
than the data. than function.

Procedural programming is based on the unreal world. Object-oriented programming is based on the real world.

Procedural programming is used for designing medium- Object-oriented programming is used for designing large
sized programs. and complex programs.

Procedural programming uses the concept of procedure Object-oriented programming uses the concept of data
abstraction. abstraction.

Code reusability absent in procedural programming, Code reusability present in object-oriented programming.
It is programmer friendly It is a machine friendly
1.
language. language.
High level language is less Low level language is high
2.
memory efficient. memory efficient.

3. It is easy to understand. It is tough to understand.

Debugging is complex
4. Debugging is easy.
comparatively.

It is complex to maintain
5. It is simple to maintain.
comparatively.

6. It is portable. It is non-portable.

7. It can run on any platform. It is machine-dependent.

It needs compiler or interpreter It needs assembler for


8.
for translation. translation.

It is used widely for It is not commonly used now-a-


9.
programming. days in programming.
 What is Language Processors?
Compilers, interpreters, translate programs written in
high-level languages into machine code that a computer
understands and assemblers translate programs written
in low-level or assembly language into machine code.
 Types of Language Processors
The language processors can be any of the following three types:
Compiler
 The language processor that reads the complete source program written in
high-level language as a whole in one go and translates it into an equivalent
program in machine language is called a Compiler. Example: C, C++, C#.
Interpreter
 The translation of a single statement of the source program into machine code is done
by a language processor and executes immediately before moving on to the next line
is called an interpreter. If there is an error in the statement, the interpreter terminates
its translating process at that statement and displays an error message.
Assembler
 The Assembler is used to translate the program written in Assembly language into
machine code.
 The source program is an input of an assembler that contains assembly language
instructions.
 The output generated by the assembler is the object code or machine code
understandable by the computer.
 Assembler is basically the 1st interface that is able to communicate humans with the
machine.
 We need an assembler to fill the gap between human and machine so that they can
communicate with each other.
 code written in assembly language is some sort of mnemonics(instructions) like ADD,
MUL, MUX, SUB, DIV, MOV and so on. and the assembler is basically able to convert these
mnemonics in binary code.
Difference Between Compiler and
Interpreter
Compiler Interpreter
A compiler is a program that converts the
An interpreter takes a source program and
entire source code of a
runs it line by line, translating each line as it
programming language into executable
comes to it.
machine code for a CPU.
The compiler takes a large amount of time to
An interpreter takes less amount of time to
analyze the entire source code but the overall
analyze the source code but the overall
execution time of the program is
execution time of the program is slower.
comparatively faster.
The compiler generates the error message
Its Debugging is easier as it continues
only after scanning the whole program, so
translating the program until the error is
debugging is comparatively hard as the error
met.
can be present anywhere in the program.
The compiler requires a lot of memory for It requires less memory than a compiler
generating object codes. because no object code is generated.
Generates intermediate object code. No intermediate object code is generated.
The interpreter is a little vulnerable in case
For Security purpose compiler is more useful.
of security.
Examples: C, C++, C# Examples: Python, Perl, JavaScript, Ruby.
Algorithm
 Definition of Algorithm
 The word Algorithm means ” A set of finite rules or instructions to be followed in
calculations or other problem-solving operations ”
Or

 ” A procedure for solving a mathematical problem in a finite number of steps that


frequently involves recursive operations”.
Use of the Algorithms:

 Algorithms play a crucial role in various fields and have many applications. Some of
the key areas where algorithms are used include:
 Computer Science: Algorithms form the basis of computer programming and are used
to solve problems ranging from simple sorting and searching to complex tasks such as
artificial intelligence and machine learning.
 Mathematics: Algorithms are used to solve mathematical problems, such as finding
the optimal solution to a system of linear equations or finding the shortest path in a
graph.
 Operations Research: Algorithms are used to optimize and make decisions in fields
such as transportation, logistics, and resource allocation.
 Artificial Intelligence: Algorithms are the foundation of artificial intelligence and
machine learning, and are used to develop intelligent systems that can perform tasks
such as image recognition, natural language processing, and decision-making.
 Data Science: Algorithms are used to analyze, process, and extract insights from large
amounts of data in fields such as marketing, finance, and healthcare.
 Properties of an Algorithm:
 1) Finiteness: - An algorithm terminates after a finite numbers of steps.
 2) Definiteness: - Each step in algorithm is unambiguous. This means
that the action
 specified by the step cannot be interpreted (explain the meaning of) in
multiple ways & can
 be performed without any confusion.
 3) Input: - An algorithm accepts zero or more inputs
 4) Output:- An algorithm should produce at least one output.
What are the Characteristics of an Algorithm?
 Step 2: Designing the algorithm
 Now let’s design the algorithm with the help of the above pre-requisites:
 Algorithm to add 3 numbers and print their sum:

1. START
2. Declare 3 integer variables num1, num2, and num3.
3. Take the three numbers, to be added, as inputs in variables num1, num2, and num3
respectively.
4. Declare an integer variable sum to store the resultant sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum.
6. Print the value of the variable sum
7. END
Flow Charts

 Flowchart is a graphical representation of an algorithm.

 It makes use of symbols which are connected among them to indicate


the flow of information and processing.
 The process of drawing a flowchart for an algorithm is known as
“flowcharting”.
 Basic Symbols used in Flowchart Designs
1. 1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic flow. A
pause/halt is generally used in a program logic under some error conditions. Terminal is the first
and last symbols in the flowchart.

2. Input/Output: A parallelogram denotes any function of input/output type. Program


instructions that take input from input devices and display output on output devices are
indicated with parallelogram in a flowchart.

3. Processing: A box represents arithmetic instructions. All arithmetic processes such as


adding, subtracting, multiplication and division are indicated by action or process symbol.
4. Decision Diamond symbol represents a decision point. Decision based operations
such as yes/no question or true/false are indicated by diamond in flowchart.

5. Connectors: Whenever flowchart becomes complex or it spreads over more than one page, it is
useful to use connectors to avoid any confusions. It is represented by a circle.

6. Flow lines: Flow lines indicate the exact sequence in which instructions are executed. Arrows
represent the direction of flow of control and relationship among different symbols of flowchart .
Question 1. Draw a flowchart to
find the greatest number among
the 2 numbers.
Solution:
Algorithm:
1. Start
2. Input 2 variables from user
3. Now check the condition If a > b, goto step
4, else goto step 5.
4. Print a is greater, goto step 6
5. Print b is greater
6. Stop
Psuedocode

 Pseudo code is a term which is often used in


programming and algorithm based fields. It is a
methodology that allows the programmer to
represent the implementation of an algorithm.

 Pseudocode is the intermediate state between an


idea and its implementation(code) in a high-level
language.
How to write Pseudocode?
 Arrange the sequence of tasks
 Start with stating main goal or the aim.
 For example: This program will allow the user to check the number
whether it's even or odd.
 Use appropriate naming conventions
 Elaborate everything or give details of process
 Use standard programming structures such as ‘if-then’, ‘for’, ‘while’,
‘cases’ the way we use it in programming.
 Check whether all the sections of a pseudo code is complete
 Don’t write the pseudo code in a complete programmatic manner.
Pseudocode::
 Input a set of 4 marks
 Calculate their average by summing and dividing by 4
 if average is below 50
Print “FAIL”
else
Print “PASS”
 Detailed Algorithm :
 Step 1: Input M1,M2,M3,M4
Step 2: GRADE  (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Start with C
 #include <stdio.h>

int main() {
printf("Hello World!");
return 0;
}
 Example explained
 Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions,
such as printf() (used in line 4). Header files add functionality to C programs.

 Don't worry if you don't understand how #include <stdio.h> works. Just think of it as something that
(almost) always appears in your program.

 Line 2: A blank line. C ignores white space. But we use it to make the code more readable.

 Line 3: Another thing that always appear in a C program is main(). This is called a function. Any code
inside its curly brackets {} will be executed.

 Line 4: printf() is a function used to output/print text to the screen. In our example, it will output "Hello
World!".

 Note that: Every C statement ends with a semicolon ;

 Note: The body of int main() could also been written as:
 int main(){printf("Hello World!");return 0;}
Statements

 A computer program is a list of "instructions" to be "executed" by a computer.


 In a programming language, these programming instructions are called statements.
 The following statement "instructs" the compiler to print the text "Hello World" to the
screen:
 Example
 printf("Hello World!");

Output (Print Text)


 To output values or print text in C, you can use the printf() function:
New Lines
To insert a new line, you can use the \n character.
The newline character (\n) is called an escape sequence,
Escape Sequence Description
\t Creates a horizontal tab
\\ Inserts a backslash character (\)

\" Inserts a double quote character

#include <stdio.h> #include <stdio.h>

int main() { int main() {


printf("Hello World!\\"); printf("They call him \"Johnny\".");
printf("I am learning C."); return 0;
return 0; }
}
Output: Output
Hello World!\I am learning C. They call him "Johnny".
Comments in C
 Comments can be used to explain code, and to make it more readable. It can also be used
to prevent execution when testing alternative code.
 Comments can be singled-lined or multi-lined.

Single-line Comments
 Single-line comments start with two forward slashes (//).

 Any text between // and the end of the line is ignored by the compiler (will not be
executed).

 This example uses a single-line comment before a line of code:

Example
 // This is a comment
 printf("Hello World!");
 Multi-line Comments

 Multi-line comments start with /* and ends with */.

 Any text between /* and */ will be ignored by the compiler:

 Example
 /* The code below will print the words Hello World!
 to the screen, and it is amazing */
 printf("Hello World!");
Tokens:
 The smallest individual units are known as tokens. C has
six types of tokens.
 1: Identifiers
 2: Keywords
 3: Constants
 4: Strings
 5: Special Symbols
 6: Operators
Identifiers:

Rules for an Identifier


1. An Identifier can only have alphanumeric characters( a-z , A-Z , 0-9 ) and underscore( _).
2. The first character of an identifier can only contain alphabet( a-z , A-Z ) or underscore ( _).
3. Identifiers are also case sensitive in C. For example name and Name are two different
identifier in C.
4. Keywords are not allowed to be used as Identifiers.
5. No special characters, such as semicolon, period, whitespaces, slash or comma are
permitted to be used in or as Identifier.
6. C‟ compiler recognizes only the first 31 characters of an identifiers.Ex : Valid
Invalid
STDNAME Return
SUB
$stay
TOT_MARKS 1RECORD
_TEMP
Keywords:
 Keywords are specific reserved words in C each of which has a
specific feature associated with it.
 Almost all of the words which help us use the functionality of
the C language are included in the list of keywords.
 There are a total of 32 keywords in C:
auto break case char const continue
default do double else enum extern
float for goto if int long
register return short signed sizeof static
struct switch typedef union unsigned void
volatile while
What is a variable in C?

 A variable in C is a memory location with some name that helps store some
form of data and retrieves it when required. We can store different types of
data in the variable and reuse the same variable for storing some other data
any number of times.

 Declaring (Creating) Variables


 To create a variable, specify the type and assign it a value:

 Syntax
 type variableName = value;
 The general rules for naming variables are:

 Names can contain letters, digits and


underscores
 Names must begin with a letter or an underscore
(_)
 Names are case-sensitive (myVar and myvar are
different variables)
 Names cannot contain whitespaces or special
characters like !, #, %, etc.
 Reserved words (such as int) cannot be used as
names
Output Variables
Format Specifier

 A format specifier starts with a percentage sign %, followed by a


character.

 It is basically a placeholder for the variable value.


int myNum = 15;
printf("%d", myNum);

To print other types, use %c for char and %f for float:


 Declaration of Variables : A variable can be used to store a value of
any data type. The
 declaration of variables must be done before they are used in the
program. The general format
 for declaring a variable.
 Syntax : data_type variable-1,variable-2,------, variable-n;
 Variables are separated by commas and declaration statement ends
with a semicolon.
 Ex : int x,y,z;
 float a,b;
 char m,n;
Assigning values to variables : values can be assigned to variables using the
assignment
operator (=). The general format statement is :
Syntax : variable = constant;
Ex : x=100;
a= 12.25;
m=‟f‟;
we can also assign a value to a variable at the time of the variable is declared. The
general format
of declaring and assigning value to a variable is :
Syntax : data_type variable = constant;
Ex ; int x=100;
float a=12.25;
char m=‟f‟;

Types of Variables in C
There are many types of variables in c:
1. local variable
2. global variable
3. static variable
C Variable Names
 All C variables must be identified with unique names.

 These unique names are called identifiers.

 Identifiers can be short names (like x and y) or more


descriptive names (age, sum, totalVolume).
Data
 Types/Types:
A datatype is a keyword/predefined instruction used for allocating memory for data.
Constants

Constants refer to fixed values that do not change during the execution of a program.
Note: constants are also called literals.

TYPES OF C CONSTANT:
1. Integer constants
2. Real or Floating point constants
3. Character constants
4. String constants
5. Backslash character constants
Two ways to define constant in C
There are two ways to define constant in C programming.
1. const keyword
2. #define preprocessor
1) C const keyword 2) C #define preprocessor
The const keyword is used to define The #define preprocessor is also used to define constant.
constant in C programming. C#define
1. const float PI=3.14; The #define preprocessor directive is used to define constant
Now, the value of PI variable can't be or micro substitution. It can use any
changed. basic data type.
1. #include <stdio.h> Syntax:
2. #include <conio.h> #define token value
3. void main(){ Let's see an example of #define to define a constant.
4. const float PI=3.14; #include <stdio.h>
5. clrscr(); 1. #define PI 3.14
6. printf("The value of PI is: %f",PI); 2. main() {
7. getch(); 3. printf("%f",PI);
8. } 4. }
Output: Output:
The value of PI is: 3.140000 3.140000
Example
// Student data
int studentID = 15;
int studentAge = 23;
float studentFee = 75.25;
char studentGrade = 'B';

// Print variables
printf("Student id: %d\n", studentID);
printf("Student age: %d\n", studentAge);
printf("Student fee: %f\n", studentFee);
printf("Student grade: %c", studentGrade);
Calculate the Area of a Rectangle In this real-life example, we create a program to calculate the
area of a rectangle (by multiplying the length and width):

Example
// Create integer variables
int length = 4;
int width = 6;
int area;

// Calculate the area of a rectangle


area = length * width;

// Print the variables


printf("Length is: %d\n", length);
printf("Width is: %d\n", width);
printf("Area of the rectangle is: %d", area);
Operators
An operator is a Symbol that performs an operation. An operators acts some
variables are called operands to get the desired result.
Ex : a+b;
Where a,b are operands and + is the operator.
Types of Operator :
1) Arithmetic Operators.
2) Relational Operators.
3) Logical Operators.
4) Assignment Operators.
5). Unary Operators.
6) Conditional Operators.
7) Special Operators.
8) Bitwise Operators.
9) Shift Operators.
Arithmetic Operators: An arithmetic operator performs mathematical operations such as addition,
subtraction and
multiplication on numerical values (constants and variables).
C Program to demonstrate the working of arithmetic operators
#include <stdio.h>
void main()
Output
{ a+b = 13
int a = 9,b = 4, c; a-b = 5
a*b = 36
c = a+b;
a/b = 2
printf("a+b = %d \n",c); Remainder when a divided by b=1
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);
 Relational Operators. A relational operator checks the relationship
between two operands.
 If the relation is true, it returns 1; if the relation is false, it returns value
0.
 Operands may be variables, constants or expressions.
 Relational operators are used in decision making and loops.
 Logical Operators.
 These operators are used to combine the results of two or more conditions. An
expression
 containing logical operator returns either 0 or 1 depending upon whether
expression results true
 or false. Logical operators are commonly used in decision making in C
programming.
// C Program to demonstrate the working of logical
operators
#include <stdio.h>
C PROGRAMMING Page 35
int main()
{
int a = 5, b = 5, c = 10, result;
Output
(a = b) && (c > b) equals to 1
result = (a = b) && (c > b);
(a = b) && (c < b) equals to 0
printf("(a = b) && (c > b) equals to %d \n", result);
(a = b) || (c < b) equals to 1
result = (a = b) && (c < b); C PROGRAMMING Page 36
printf("(a = b) && (c < b) equals to %d \n", result); (a != b) || (c < b) equals to 0
result = (a = b) || (c < b); !(a != b) equals to 1
printf("(a = b) || (c < b) equals to %d \n", result); !(a == b) equals to 0
result = (a != b) || (c < b);
printf("(a != b) || (c < b) equals to %d \n", result);
result = !(a != b);
printf("!(a == b) equals to %d \n", result);
result = !(a == b);
printf("!(a == b) equals to %d \n", result);
return 0;
}
 Assignment Operators. Assignment operators are used to assign a value (or) an
expression
 (or) a value of a variable to another variable.
 Syntax : variable name=expression (or) value (or) variable
 Ex : x=10;
 y=a+b;
 z=p;
Compound assignment operator:
 „C‟ provides compound assignment operators to assign a value to variable in order to
assign a
 new value to a variable after performing a specified operation.
Increment and Decrement Operators /Unary Operators:
Increment Operator in C Programming
1. Increment operator is used to increment the current value of variable by adding integer 1.
2. Increment operator can be applied to only variables.
3. Increment operator is denoted by ++.
We have two types of increment operator i.e Pre-Increment and Post-Increment Operator.

Pre-Increment:
b = ++y;
In this example suppose the value of variable „y‟ is 5 then value of variable „b‟ will be 6 because
the value of „y‟ gets modified before using it in a expression.

Post-Increment:
b = x++;
In this example suppose the value of variable „x‟ is 5 then value of variable „b‟ will be 5 because
old value of „x‟ is used.
Bit Wise Operator
Special operators :-
--------------------------------------
C language provides 2 types of special operators.
a. Sizeof()
b. Comma( , )

Sizeof() :-
------------------

It gives the size of operand.


Example :
#include<stdio.h>
void main()
{
printf("Size of char =%d",sizeof(char));
printf("\nSize of int =%d",sizeof(int));
printf("\nSize of float =%d",sizeof(float));
printf("\nsize of double =%d",sizeof(double));
}
Output :
Size of char =1
Size of int =4
Size of float =4
size of double =8
 Expressions
 Expressions : An expression is a combination of operators and operands which reduces to
a single value. An operator indicates an operation to be performed on data that yields a
value. An operand is a data item on which an operation is performed.
 A simple expression contains only one operator.
 Ex : 3+5 is a simple expression which yields a value 8, -a is also a single expression.
 A complex expression contain more than one operator.
* WAP to read 2 numbers. Swap the numbers.
* WAP to swap 2 numbers without using third variable.
* WAP to find the sum of N natural numbers without using any loop.
* WAP to read basic, hra, da, pf. Find the net salary.
Net = basic + hra + da – pf

*WAP to read a upper case char, convert it to lower case.


* WAP to read input and check the input is character or digit or
special symbol.
*WAP to read a integer no. and check is it divisible by 9 or not.
*WAP to read a integer no. and check is it divisible by 6 or not.
*WAP to read a integer no. and check is it divisible by 5 or not.
3. WAP to read a number. Print whether it is +ve number or –ve number.
If else ladder / Stair case if / if else – if else –if
Syntax :
if( condition )
{
body
}
else if( condition )
{
body;
}
…..
else
{
body;
}
#include<stdio.h>
void main()
{
int avg;
printf("Enter avg marks : ");
scanf("%d",&avg);
if( avg>=60 )
printf("I Class");
else if( avg>=50 )
printf("II Class");
else
printf("III Class");
}
WAP to read sales done by a sales man. Print the commission based on
following table.
Sales Commission
<5000 0
<10000 200
Else 400
WAP to read age of a person print the message based on
following table.
Age Message
<3 Infants
<16 Kids
<21 Teenagers
<28 Youngster
s
<40 Middle
agers
Else Old agers
WAP read age, gender of a person. Print whether the person is major or minor.
Gender Age Message
<21 Minor
M
else major

<18 Minor
F
else major
Switch :-
---------------------------------- case constantN : body; break;
❖ It is a control statement. default: body;
}
❖ It is a decision making statement.
❖ It is a conditional statement.
❖ It is multi way selection statement.
❖ It is a branching statement.
❖ It is used when we need to select a single choice from group of
choices.
Syntax :
switch ( expression )
{
case constant1: body; break;
case constant2: body; break;
case constant3: body; break;

WAP to read a single digit number.
Spell it.
case 4: printf("Four"); break;
#include<stdio.h> case 5: printf("Five"); break;
void main() case 6: printf("Six"); break;
case 7: printf("Seven"); break;
{ case 8: printf("Eight"); break;
case 9: printf("Nine"); break;
int no; default: printf("Invalid input");
printf("enter a single digit number : }
"); }

scanf("%d",&no);
Output1 :
switch( no ) Enter a single digit number : 5
{ Five
Output2 :
case 0: printf("Zero"); break;
case 1: printf("One"); break;
case 2: printf("Two"); break;
While :-
-------------------
❖ It is a control statement
❖ It is a conditional statement.
❖ It is an iterative tool.
❖ It is a pre test loop.
❖ It is used to execute the code repeatedly.
Syntax :
while( condition )
{
Body;
}
1. WAP to print your name 5 times.
#include<stdio.h>
void main()
{
int i=1;
while( i<=5 )
{
printf("\nHello World");
i++;
}
}
3. WAP to print odd numbers from 1 to 100.
#include<stdio.h>
void main()
{
int no=1;
while( no<=100 )
{
printf("%5d",no);
no+=2;
}
}
Output :
1 3 5 7 9 … 99
For :-
❖ It is a control statement.
❖ It is a conditional statement.
❖ It is an iterative statement.
❖ It is a pre test loop.
❖ It can carry initialization, condition and inc/dec in one line.
Syntax :
for( initialization ; condition ; inc/dec )
{
Body;
}
Note :
❖ If there are more than one initialization then we have to separate them by
camma.
❖ If there are multiple increments or decrements then we have to separate
them by camma.
WAP to read a number. Print the multiplication
table.
#include<stdio.h>
void main()
{
int no,i;
printf("Enter a number : ");
scanf("%d",&no);
for( i=1;i<=10;i++) Output :
Enter a number : 5
printf("\n%d*%d=%d",no,i,no*i); 5*1=5
} 5*2=10
5*3=15

5*10=50
Do-While :-
It is a control statement.
It is a conditional statement.
It is an iterative statement.
it is used to execute the code repeated.
It is a post test loop.
The body will execute at least once.
It is used when we don’t know exact count of iteration.
Syntax :

do
{
body;
}while( condition );
WAP to find sum of elements entered by user.
#include<stdio.h>
Output :
void main()
Enter a number : 1
{ Do want to add one more? y
int no,sum=0; char ch; Enter a number : 2
Do want to add one more? y
do Enter a number : 3
{ Do want to add one more? y
Enter a number : 4
printf("\nEnter a number : "); Do want to add one more? y
scanf("%d",&no); Enter a number : 5
sum=sum+no; Do want to add one more? n
printf("\nDo want to add one more? "); Sum=15
scanf(" %c",&ch);
}while( ch!='n’);
printf("Sum=%d",sum);
}
Break :-

 It is a control statement.
 It is an un conditional statement.
 It is used to stop the loop at middle.
 It can be used only with switch, while, for, do-while.
Example :
#include<stdio.h> void main()
{
int no;
for(no=1;no<=100;no++)
{
printf("%5d",no);
if( no==10 )
break;
}
}
Output :-
1 2 3 4 5 6 7 8 9 10
Continue :-
 It is a control statement.
 It is a decision making statement.
 It is a un conditional statement.
 It is used to skip the rest of the code of current iteration.
 It can be used only with while, for, do-while.
Example :
#include<stdio.h> void main()
{
int no;
for(no=1;no<=100;no++)
{
if( no%2==0 ) continue;
printf("%5d",no);
}
}
Output :
1 3 5 7 9 …. 99
Goto :-
 It is a control statement.
 It is a un conditional statement.
 It is a decision making statement.
 It is used to move the control from one location to another
location.
 It move the cursor to the specified Lable.
 Label is a name which always ends with “:” symbol
Example :
#include<stdio.h>
void main()
{
printf("\none");
goto ss;
printf("\ntwo");
printf("\nthree");
ss:
printf("\nfour");
printf("\nfive");
}
Output :
One
four
five

You might also like