SlideShare a Scribd company logo
1 of 37
Download to read offline
Problem Solving and Programming using C
UNIT II
Programming Style – Tokens of C, Keywords, Variables, Constants and rules to form variables and
constants, Data Types, Declaration of Variables and initialization, Operators, operator precedence and
associativity, Type conversions.
Flow of Control: Selection: if and if-else Statements, if-else if statement and switch case, nested if,
examples.
Repetition and Unconditional Control Statements: while Statement, do while statement, for
Statement, nested loops, break, continue, goto.
TOPIC 1: TOKENS OF C:
 C tokens are the basic buildings blocks in C language which are constructed together
to write a Cprogram.
 Each and every smallest individual units in a C program are known as C tokens.
C tokens example program:
int main() main – keyword
{ {,}, (,) – delimiter
int x, y, total; keyword x, y, total – identifier
x = 10, y = 20;
total = x + y;
printf ("Total = %d n", total); main, {, }, (, ), int, x, y, total – tokens
}
C tokens are of six types. They are,
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special charaters
6. Operators
Keywords in C language:
 Keywords are pre-defined words in a C compiler.
 Each keyword is meant to perform a specific function in a C program.
 Since keywords are referred names for compiler, they can’t be used as variable name.
C language supports 32 keywords which are given below.
auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double
2. Identifiers in C language:
 Each program elements in a C program are given a name called identifiers.
 Names given to identify Variables, functions and arrays are examples for identifiers.
eg. x is a namegiven to integer variable in above program.
Rules for constructing identifier name in C:
1. First character should be an alphabet or underscore.
2. Succeeding characters might be digits or letter.
3. Punctuation and special characters aren’t allowed except underscore.
Identifiers should not be keywords.
3. C constants
C Constants are also like normal variables. But, only difference is, their values can not be
modified by the program once they are defined.
 Constants refer to fixed values. They are also called as literals
 Constants may be belonging to any of the data type.
 Syntax:
const data_type variable_name = value; (or) #define variable_name value
Types of C constant:
1. Integer constants
2. Real or Floating point constants
3. Octal & Hexadecimal constants
4. Character constants
5. String constants
6. Backslash character constants
Constant type data type (Example)
Integer constants
int (53, 762, -478 etc )
unsigned int (5000u, 1000U etc)long int, long
long int (483,647 2,147,483,680)
Real or Floating point constants float (10.456789)
doule (600.123456789)
Octal constant int (Example: 013 /*starts with 0 */)
Hexadecimal constant int (Example: 0x90 /*starts with 0x*/)
character constants char (Example: ‘A’, ‘B’, ‘C’)
string constants char (Example: “ABCD”, “Hai”)
Rules for constructing C constant:
1. Integer Constants in C:
 An integer constant must have at least one digit.
 It must not have a decimal point.
 It can either be positive or negative.
 No commas or blanks are allowed within an integer constant.
 If no sign precedes an integer constant, it is assumed to be positive.
 The allowable range for integer constants is -32768 to 32767.
2. Real constants in C:
 A real constant must have at least one digit
 It must have a decimal point
 It could be either positive or negative
 If no sign precedes an integer constant, it is assumed to be positive.
 No commas or blanks are allowed within a real constant.
3. Character and string constants in C:
 A character constant is a single alphabet, a single digit or a single special symbol
enclosed withinsingle quotes.
 The maximum length of a character constant is 1 character.
 String constants are enclosed within double quotes.
4. Backslash Character Constants in C:
 There are some characters which have special meaning in C language.
 They should be preceded by backslash symbol to make use of special function of them.
 Given below is the list of special characters and their purpose.
Backslash character Meaning
b Backspace
f Form feed
n New line
r Carriage return
t Horizontal tab
” Double quote
’ Single quote
 Backslash
v Vertical tab
a Alert or bell
? Question mark
N Octal constant (N is an octal constant)
XN Hexadecimal constant (N – hex.dcml cnst)
How to use constants in a C program?
We can define constants in a C program in the following ways.
1. By “const” keyword
2. By “#define” preprocessor directive
Variables:
 C variable is a named location in a memory where a program can manipulate the
data. This location isused to hold the value of the variable.
 The value of the C variable may get change in the program.
 C variable might be belonging to any of the data type like int, float, char etc.
Rules for naming C variable:
1. Variable name must begin with letter or underscore.
2. Variables are case sensitive
3. They can be constructed with digits, letters.
4. No special symbols are allowed other than underscore.
5. sum, height, _value are some examples for variable name
Declaring & initializing C variable:
 Variables should be declared in the C program before to use.
 Memory space is not allocated for a variable while declaration. It happens only on variable
definition.
 Variable initialization means assigning a value to the variable.
Type Syntax
Variable declaration data_type variable_name;
Example: int x, y, z; char flat, ch;
Variable initialization data_type variable_name = value;
Example: int x = 50, y = 30; char flag = ‘x’, ch=’l’;
Key Differences between Identifier and Variable:
1. Both an identifier and a variable are the names allotted by users to a particular entity in a
program. The identifier is only used to identify an entity uniquely in a program at the time of
execution whereas, a variable is a name given to a memory location, that is used to hold a value.
2. Variable is only a kind of identifier, other kinds of identifiers are function names, class names,
structure names, etc. So it can be said that all variables are identifiers whereas, vice versa is not
true.
As identifier and variable names are user-defined names, it should be taken care that no two identifiers
or no two variable names in a program should be the same. It will create a problem of ambiguity in a
program.
TOPIC 4: DATA TYPES
Data types in c refer to an extensive system used for declaring variables or functions of
different types. The typeof a variable determines how much space it occupies in storage and
how the bit pattern stored is interpreted.
The types in C can be classified as follows –
Integer Types
The following table provides the details of standard integer types with their storage sizes and
valueranges −
Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to
2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
To get the exact size of a type or a variable on a particular platform, you can use the sizeof
operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.
Floating-Point Types
The following table provide the details of standard floating-point types with storage
sizes and value rangesand their precision −
Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
TOPIC 5: OPERATORS
Operators in C Language:
C language supports a rich set of built-in operators. An operator is a symbol that tells the
compiler to performcertain mathematical or logical manipulations. Operators are used in
program to manipulate data and variables.
C operators can be classified into following types,
 Arithmetic operators
 Relational operators
 Logical operators
 Bitwise operators
 Assignment operators
 Conditional operators (ternary operator)
 Special operators (sizeof (), comma)
Arithmetic operators
C supports all the basic arithmetic operators. The following table shows all the basic arithmetic
operators.
Ope
rato
r
Description Synta
x
E
x
+ adds two operands Operand + operand A+B 4+2
- subtract second operands from first Operand - operand A-B 4+2
* multiply two operand Operand * operand A*B 4+2
/ divide numerator by denominator Operand / operand A/B 4+2
% remainder of division Operand % operand A%B 4+2
++ Increment operator increases integer value
byone
operand++,
++operand
A++
++A
4+2
-- Decrement operator decreases integer
valueby one
Operand--
--operand
A--
--A
4+2
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“sum of a and b is %d”,c);
d=a-b;
printf(“sbtraction of a and b is %d”,d);
e=a*b;
printf(“multiplication of a and b is %d”,e);
f=a/b;
printf(“division of a and b is %d”,f);
g=a%b;
printf(“modulo of a and b is %d”,g);
}
Relation operators
Relation operators are used to specify the relation between two operands such as greater
than, less than, equalto and etc.
If the relation between two operands is true then the result is one (1) otherwise zero(0).
Assume variable A holds 10 and variable B holds 20 then
Operato
r
Description Example Outp
ut
== Check if two operand are
equal
A==B Is not true gives 0 as output
!= Check if two operand
are notequal.
A!=B Is true gives 1 as output
> Check if operand on the
left is greater than operand
on the right
A>B Is not true gives 0 as output
< Check operand on the
left issmaller than right
operand
A<B Is true gives 1 as output
>= check left operand is
greater thanor equal to
right operand
A>=B Is not true gives 0 as output
<= Check if operand on left
is smaller than or equal
to rightoperand
A<=B Is true gives 1 as output
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,; printf(“enter
a,b:”);
scanf(“%d%d”,&a,&b);
printf(“result for greater than relation operator when its true %d”, a>b);
printf(“result for less than relation operator when its true %d”, a<b);
printf(“result for greater than or equal relation operator when its true %d”, a>=b);
printf(“result for less than or equal relation operator when its true %d”, a<=b);
printf(“result for equal relation operator when its true %d”, a==b);
printf(“result for not equal relation operator when its true %d”, a!=b);
}
Logical operators
Logical operators are used to perform operations on more than one expression.
C language supports following 3 logical operators. Suppose a=1 and b=0,
Operator Descripti
on
Example
&& Logical AND:Called Logical AND operator. If both the
operands are non-zero, then the condition becomes true.
(a && b)
isfalse
|| Logical OR: Called Logical OR Operator. If any of the two
operands is non-zero, then the condition becomes true.
(a || b) is
true
! Logical NOT:Called Logical NOT Operator. It is used to
reverse the logicalstate of its operand. If a condition is true,
then Logical NOT operator will make it false.
(!a) is false
Program:
#include<stdio.h>
#include<conio.h> Void
main()
{
int a,b,c,d,e;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a&&b;
d=a||b
;e=!a;
printf(“result for logical and is %d”,c);
printf(“result for logical or is %d”,d);
printf(“result for logical not is %d”,e);
}
Bitwise operators:
Bitwiseoperators perform manipulations of data at bit level. These operators also perform
shifting of bits fromright to left. Bitwise operators are not applied to float or double.
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is
as follows –
Assume variable 'A' holds 60 and variable 'B' holds 13, then –
Operator Descripti
on
Example
& Bitwise AND:Operator copies a bit to the result if it exists in both
operands.
(A & B) =
12, i.e.,
0000 1100
| Bitwise OR: Operator copies a bit if it exists in either operand. (A | B) = 61,
i.e.,0011
1101
^ Bitwise exclusive OR: Operator copies the bit if it is set in one
operand butnot both.
(A ^ B) =
49, i.e.,
0011 0001
~ Binary Ones Complement Operator is unary and has the
effect of 'flipping'bits.
(~A ) = -61,
i.e,.1100
0011 in 2's
compleme
ntform
<< Binary Left Shift:The left operands value is moved left by
the number ofbits specified by the right operand.
A << 2 = 240
i.e., 1111 0000
>> Binary Right Shift: The left operands value is moved right by
the number ofbits specified by the right operand.
A >> 2 = 15
i.e.,
0000 1111
Now let’s see truth table for bitwise &, | and ^
a b a &
b
a |
b
a ^
b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
The bitwise shift operators shifts the bit value. The left operand specifies the value to be
shifted and the rightoperand specifies the number of positions that the bits in the value are
to be shifted. Both operands have the same precedence.
Example:
Assume A = 60 and B = 13 in binary format, they will be
as follows −A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Program
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a&b;
d=a|b;
e=a^b;
f=a<<4;
g=b>>3;
printf(“result for bitwise and is %d”,c);printf(“result for bitwise or is %d”,d);
printf(“result for bitwise not is %d”,e);printf(“result for left shift is %d”,f);
printf(“result for right shift is %d”,g);
}
Assignment Operators
we explored how results are displayed and how numerical data are stored and processed using
variables andassignment statements.
Assignment operator (=) is used for assignment a value to a variable and for performing
computations.Assignment statement has the syntax:
variable = expression;
Expression is any combination of constants, variables, and function calls that can be evaluated to
yield a result.
Example:
length = 25;
cMyCar = “Mercedes”;
sum = 3 + 7;
newtotal = 18.3*amount;
slope = (y2 – y1)/(x2 – x1);
Assignment operators supported by C language are as follows.
Operato
r
Descripti
on
Examp
le
= assigns values from right side operands to left side operand a=b,
c=a+b
+= adds right operand to the left operand and assign the result
to left
a+=b is same as a=a+b
-= subtracts right operand from the left operand and assign
the result toleft operand
a-=b is same as a=a-b
*= mutiply left operand with the right operand and assign
the result toleft operand
a*=b is same as a=a*b
/= divides left operand with the right operand and assign
the result toleft operand
a/=b is same as a=a/b
%= calculate modulus using two operands and assign the
result to leftoperand
a%=b is same as
a=a%b
<<= Left shift AND assignment operator. C <<= 2 is same as C =
C
<< 2
>>= Right shift AND assignment operator. C >>= 2 is same as C =
C
>> 2
&= Bitwise AND assignment operator. C &= 2 is same as C =
C &2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C
= C ^2
|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C
| 2
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&
b);c+=b;
d-
=a;
e*=b
;
a/=2;
printf(“result for assignment operator is
%d”,c); printf(“result for assignment
operator is %d”,d); printf(“result for
assignment operator is %d”,e);
printf(“result for assignment operator is
%d”,a);
}
Special operators
Operato
r
Description Examp
le
sizeof Returns the size of an
variable
sizeof(x) return size of the
variable x
& Returns the address of an
variable
&x ; return address of the
variable x
* Pointer to a variable *x ; will be pointer to a
variable x
Comma Separate variables,
expressions
Int a,b,c;
Conditional operator
It is also known as ternary operator and used to evaluate conditional
expression. Conditional operator returns one value when condition is true
otherwise returns other value.
If condexpr is true ? Then the value isstatement 1 : Otherwise value statement 2.
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=(a>b)?a:b;
printf(“result for conditional operator is %d”,c);
}
Conditional expression ? statement1 : statement2
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 ++.
Different Types of Increment Operation
In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment
Operator.
A. Pre Increment Operator
Pre-increment operator is used to increment the value of variable before using in the
expression. In the Pre-Increment value is first incremented and then used inside the
expression.
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.
Sample program
Output :
Value of a :
11Value of
x: 11
B. Post Increment Operator
Post-increment operator is used to increment the value of variable as soon as after executing
expression completely in which post increment is used. In the Post-Increment value is first
used in a expression and then incremented.
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.
Sample program
#include<stdio.h>
void main()
{
int a,x=10;
a = ++x;
printf("Value of a : %d",a);
printf("Value of x : %d",x);
}
#include<stdio.h>
void main()
{
inta,b,x=10;
a = x++;
printf("Value of a : %d",a);
printf("Value of a : %d",x);
}
Output :
Value of a :
10Value of
x : 11
Decrement Operator in C Programming :
1. Decrement operator is used to decrease the current value of variable by subtracting integer 1.
2. Like Increment operator, decrement operator can be applied to only variables.
3. Decrement operator is denoted by –.
Different Types of Decrement Operation :
When decrement operator used in C Programming then it can be used as pre-decrement or
post-decrementoperator.
A. Pre Decrement Operator
Pre-decrement operator is used to decrement the value of variable before using in the
expression. In the Pre-decrement value is first decremented and then used inside the
expression.
b = --var;
Suppose the value of variable var is 10 then we can say that value of variable ‘var’ is firstly
decremented thenupdated value will be used in the expression.
C Program
Output :
Value of a
: 9Value of
y : 9
B. Post Decrement Operator
Post-decrement operator is used to decrement the value of variable immediatly after
executing expression completely in which post decrement is used. In the Post-decrement
old value is first used in a expression andthen old value will be decrement by 1.
b = var--;
#include<stdio.h>
void main()
{
intb,y=10;
b = --y;
printf("Value of b : %d",b);
printf("Value of y : %d",y);
}
Value of variable ‘var’ is 5. Same value will be used in expression and after execution of
expression new valuewill be 4.
C Program
Output :
Value of a :
10Value of
x : 9
Operator precedence and associativity:
Symbol (4M) Type of Operation
(2M)
Associativity(2M)
[ ] ( ) . –> postfix ++ and postfix –– Expression Left to right
prefix ++ and prefix –– sizeof & *
+ – ~ !
Unary Right to left
typecasts Unary Right to left
* / % Multiplicative Left to right
+ – Additive Left to right
<< >> Bitwise shift Left to right
< > <= >= Relational Left to right
== != Equality Left to right
& Bitwise-AND Left to right
^ Bitwise-exclusive-OR Left to right
| Bitwise-inclusive-OR Left to right
&& Logical-AND Left to right
|| Logical-OR Left to right
#include<stdio.h>
void main()
{
inta,x=10;
a = x--;
printf("Value of a : %d",a);
printf("Value of x : %d",x);
}
? : Conditional-
expression
Right to left
= *= /= %=
+= –= <<= >>= &=
^= |=
Simple and
compound
assignment
Right to left
, Sequential
evaluation
Left to right
TOPIC 8: EXPRESSION
TYPES
C Programming Expression:
1. In programming, an expression is any legal combination of symbols that represents a value.
2. C Programming provides its own rules of Expression, whether it is legal
expression or illegalexpression. For example, in the C language x+5 is a legal
expression.
3. Every expression consists of at least one operand and can have one or more operators.
4. Operands are values and Operators are symbols that represent particular actions.
Valid C Programming Expression:
C Programming code gets compiled firstly before execution. In the different phases of compiler, c
programmingexpression is checked for its validity.
Expressions Validit
y
a + b Expression is valid since it contain + operator which is binary operator
+ + a + b Invalid Expression
Priority and Expression:
In order to solve any expression we should have knowledge of C Programming Operators and their
priorities.
Types of Expression:
In Programming, different verities of expressions are given to the compiler. Expressions can
be classified on thebasis of Position of Operators in an expression –
Type Explanati
on
Example
Infix Expression in which Operator is in between Operands a + b
Prefix Expression in which Operator is written before Operands + a b
Postfix Expression in which Operator is written after Operands a b +
Type ConversionsType casting is a way to convert a variable from one data type to another
data type. For example, if you want to store a long value into a simple integer then you can
type cast long to int. You can convert values from one type to another explicitly using the
cast operator. New data type should be mentionedbefore the variable name or value in
brackets which to be typecast.
There are two types of type casting in c language.
1. Implicit conversion:
 Implicit conversions do not required any operator for converted. They are
automatically performedwhen a value is copied to a compatible type in program.
 Here, the value of a has been promoted from int to double and we have not had to
specify any type-casting operator. This is known as a standard conversion.
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int i;
float f;
double d;
long int l;
x=l/i+i*f-d;
printf(“%d”,x);
}
2. Explicit conversion
In c language, many conversions, especially those that imply a different interpretation of
the value, require anexplicit conversion. We have already seen two notations for explicit
type conversion.
Syntax: (data type) expression;
They are not automatically performed when a value is copied to a compatible type in program.
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int n;
float sum=0;
for(n=1;n<=10;n
++)
sum=sum+1/float
(n);printf(“
%f”,sum);
}
}
In the above example, n declares as integer after that its converted into float so
the result also bein float data type only.
TOPIC 9: FLOW OF CONTROL
Control Flow-Relational Expressions - Logical Operators
Control Structures are those statements that decide the order in which individual statements or
instructions of aprogram are executed or evaluated.
Control Structures are broadly classified into:
1. Conditional statements: Specifies a condition to execute a group of
statements in a program.The control structures, if, if-else, nested if, if else ladder
and switch, belongs to this category.
2. Iterative statements: Executes one or more statements repeatedly until a
condition is met.The control structures: while, do...while, and for loops, belong
to this category.
3. Jump statements: Transfer of control from one part to another within the
program. Ex. goto,break, continue and return.
Selection: if-else Statement, nested
if Single way selection (Simple if
statement)
The if statements executes a simple or compound statements, depending on whether or not an
expression is trueof false.
The syntax
if(conditional expression)
statements; // single statement
if(conditional expression)
{
//compound
statements
statement 1;
statement 1;
statement 1;
}
The flow chart for the single-way decision logic is shown.
In the preceding syntaxes, a simple or compound statement (block of statements) is executed
when the condition expression is true. Otherwise, the program control passes to next
statement. If the condition expression is false then the C compiler does not do anything.
Note that the condition expression given in parenthesis, must be evaluated as true (non-zero
value) or false (zerovalues). In addition, a compound statement must be provided by opening
and closing braces.
Examples:
if(7) // a non zero value returns
true if(0) //zero value returns
false if(i==0) //True if i=0
other wise False
if(i=0) //false because value of the expression is zero
Program:
#include<stdio
.h>main()
{
int
a,b,c,d;
float
ratio;
printf(“enter a,b,c,d values ”);
scanf(“%d%d%d%d”,&a,&b,&
c,&d);if(c-d!=0)
{
ratio=(float)(a+b)/(float)
(c-d);printf(“the ratio is
%f”,ratio);
}
Output:
Enter a,b,c,d values 11
12 7 5The ratio is
11.500000
Two - way selection (if-else statement)
The basic decision statement in the computer is the two-way selection. If the condition is
true, one or moreaction statements are executed. If the condition is false, then a different
action or set of actions is executed.
Syntax:
if(conditional-expression)
{
}
els
e
{
}
true-block statements;
false-block Statements;
The flow chart for the two-way decision logic is shown.
Example: write a C code to find biggest of two numbers using if-else statement
#include<stdio
.h>void main()
{
int a,b;
printf(“enter two
values”);
scanf(“%d%d”,&a,&
b);
if(a>b)
{
}
els
e
{
}
}
printf(“%d is Big Value”,a);
printf(“%d is Big Value”,b);
Null else, nested if, examples
Null Else: if else statement does not have any executable statements then it is consider as null
else statement. Soelse part will contain only (;) because it doesn’t have any executable
statements.
The syntax is as follows:
if(test-condition)
{
true-block statements;
}
else;
Example:
if(sal>10000)
{
sal=sal+1000;
}
else;
Nested if statement
When an if-else is included within an if-else, it is known as a nested if statement. The
control of a programmoves into the inner if statements when the outer if statement is
evaluated to be true.
Include one condition within another condition is known as nested if.
Syntax of nested if statement:
if (test expression1)
{
if(test expression2)
{
Statement-1;
}
else
{
Statement-2;
}
els
e
{
}
if(text expression-3)
{
statement-3;
}
else
{
statement-4;
}
}
Flowchar
t:
.
Example of nested if statement : write C code to find the biggest of three number
#include<stdio
.h>Void
main()
{
int a,b;
printf(“enter three values”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
printf(“Biggest
Number=%d”,a);else
printf(“Biggest number=%d”,c);
}
else
{
if(b>c)
printf(“Biggest Number=%d”,b);
else
printf(“Biggest number=%d”,c);
}
}
Example:
#include<stdio
.h>main()
{
int
password;
char
username;
printf(“enter user
name”);
scanf(“%c”,&userna
me); printf(“enter
password”);
scanf(“%d”,&passwo
rd);
if(username==’a’)
{
If(password==123)
printf(“login sucessfull”);
}
els
e
els
e printf(“Invalid password”);
printf(“invalid user name”);
}
Example programs on simple if and if-else
statementsProgram:
#include<stdio
.h>main()
{
int
a,b,c,d;
float
ratio;
printf(“enter a,b,c,d values ”);
scanf(“%d%d%d%d”,&a,&b,&
c,&d);if(c-d!=0)
{
ratio=(float)(a+b)/(float)
(c-d);printf(“the ratio is
%f”,ratio);
}
Output:
Enter a,b,c,d values 11
12 7 5The ratio is
11.500000
example: write a C code to find biggest of two numbers using if-
else statement#include<stdio.h>
void main()
{
int a,b;
printf(“enter two
values”);
scanf(“%d%d”,&a,&
b);
if(a>b)
{
}
els
e
{
}
}
printf(“%d is Big Value”,a);
printf(“%d is Big Value”,b);
Example programs on nested if
Example of nested if statement : write C code to find the biggest of three
number#include<stdio.h>
Void main()
{
int a,b;
printf(“enter three values”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
printf(“Biggest
Number=%d”,a);else
printf(“Biggest number=%d”,c);
}
else
{
if(b>c)
printf(“Biggest
Number=%d”,b);else
printf(“Biggest number=%d”,c);
}
}
Example:
#include<stdio
.h>main()
{
int
password;
char
username;
printf(“enter user
name”);
scanf(“%c”,&userna
me); printf(“enter
password”);
scanf(“%d”,&passwo
rd);
if(username==’a’)
{
If(password==123)
printf(“login sucessfull”);
else
}
els
e
printf(“Invalid password”);
printf(“invalid user name”);
}
Multi-way selection: switch,
else-if,The switch statement
 The switch statement can be used to make multi-way decisions
 It is especially good when you have many cases to choose from
 There are still situations where you do have to use if statements, however
The Syntax of switch
switch (expression)
{
case (expression) :
Statements;
break;
case (expression):
Statements;
break;
// more cases can go here
default: Statements;
}
The following rules apply to a switch statement −
 The expression used in a switch statement must have an integral or enumerated
type, or be of a classtype in which the class has a single conversion function to an
integral or enumerated type.
 You can have any number of case statements within a switch. Each case is followed
by the value to becompared to and a colon.
 The constant-expression for a case must be the same data type as the variable in
the switch, and itmust be a constant or a literal.
 When the variable being switched on is equal to a case, the statements following that
case will executeuntil a break statement is reached.
 When a break statement is reached, the switch terminates, and the flow of control
jumps to the nextline following the switch statement.
 Not every case needs to contain a break. If no break appears, the flow of control
will fall through tosubsequent cases until a break is reached.
 A switch statement can have an optional default case, which must appear at the end
of the switch. Thedefault case can be used for performing a task when none of the
cases is true. No break is needed in the default case.
Flow Diagram
Else-if ladder Statement
An if statement can be followed by an optional else if...else statement, which is very
useful to test variousconditions using single if...else if statement.
When using if...else if..else statements, there are few points to keep in mind −
 An if can have zero or one else's and it must come after any else if's.
 An if can have zero to many else if's and they must come before the else.
 Once an else if succeeds, none of the remaining else if's or else's will be tested.
Syntax
The syntax of an if...else if...else statement in C programming
language is −if(expression 1)
{
Statement 1;
}
else if(expression 2)
{
Statement 2;
}
else if(expression 3)
{
}
els
e
{
}
Statement 3;
Statement 4;
Flowchart:
Programs on switch
caseExample
#include<stdio.
h>
#include<conio
.h>
#include<math.
h> void main()
{
Int a,b,c,ch;
clrscr();
printf("nenter value of a
and b:");scanf("%d
%d",&a,&b);
printf("nlist:n1.Additionn2.Subtractionn3.Multiplicationn
4.Modulus");printf("nEnteryour choice:");
scanf("%d",&ch);
switch(ch)
{
case 1: c=a+b;
brea
k;case2:
c=a-b;
brea
k;case 3:
c=a*b;
brea
k;case 4:
c=a/b;
break;
default: printf("wrong
option");break;
}
printf("nResult of %d and %d is
%d",a,b,c);getch();
}
Example programs on else if
ladderExample
#include
<stdio.h>void
main ()
{
int a =
100; if( a
== 10 )
{
printf("Value of a is 10n" );
}
else if( a == 20 )
{
printf("Value of a is 20n" );
}
else if( a == 30 )
{
printf("Value of a is 30n" );
}
else
{
printf("None of the values is matchingn" );
}
printf("Exact value of a is: %dn", a );
}
Example:
#include<stdio
.h>main()
{
int marks;
printf(“enter your
marks”);
scanf(“%d”,&marks);
if(marks>=90)
printf(“YOUR GRADE
:An”);else if(marks>=70 &&
marks<90)
printf(“YOUR GRADE:
Bn”);else if(marks>=50 &&
marks<70)
printf(“YOUR GRADE:Cn”);
else
}
printf(“YOUR GRADE: FAILEDn”);

More Related Content

Similar to PSPC--UNIT-2.pdf

datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c languageRai University
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageRai University
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic conceptsAbhinav Vatsa
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C languageSachin Verma
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
 
Learn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsLearn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsEng Teong Cheah
 
Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming LanguageRamaBoya2
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++Rokonuzzaman Rony
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language Rowank2
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptxRowank2
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdfAdiseshaK
 

Similar to PSPC--UNIT-2.pdf (20)

C
CC
C
 
datatypes and variables in c language
 datatypes and variables in c language datatypes and variables in c language
datatypes and variables in c language
 
Btech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c languageBtech i pic u-2 datatypes and variables in c language
Btech i pic u-2 datatypes and variables in c language
 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Diploma ii cfpc u-2 datatypes and variables in c language
Diploma ii  cfpc u-2 datatypes and variables in c languageDiploma ii  cfpc u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
 
Basic of the C language
Basic of the C languageBasic of the C language
Basic of the C language
 
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...
 
C introduction
C introductionC introduction
C introduction
 
C material
C materialC material
C material
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
Learn C# Programming - Variables & Constants
Learn C# Programming - Variables & ConstantsLearn C# Programming - Variables & Constants
Learn C# Programming - Variables & Constants
 
Fundamentals of C Programming Language
Fundamentals of C Programming LanguageFundamentals of C Programming Language
Fundamentals of C Programming Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
Basics of c
Basics of cBasics of c
Basics of c
 
Interview Questions For C Language
Interview Questions For C Language Interview Questions For C Language
Interview Questions For C Language
 
Interview Questions For C Language .pptx
Interview Questions For C Language .pptxInterview Questions For C Language .pptx
Interview Questions For C Language .pptx
 
C programming notes.pdf
C programming notes.pdfC programming notes.pdf
C programming notes.pdf
 

Recently uploaded

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 

Recently uploaded (20)

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 

PSPC--UNIT-2.pdf

  • 1. Problem Solving and Programming using C UNIT II Programming Style – Tokens of C, Keywords, Variables, Constants and rules to form variables and constants, Data Types, Declaration of Variables and initialization, Operators, operator precedence and associativity, Type conversions. Flow of Control: Selection: if and if-else Statements, if-else if statement and switch case, nested if, examples. Repetition and Unconditional Control Statements: while Statement, do while statement, for Statement, nested loops, break, continue, goto. TOPIC 1: TOKENS OF C:  C tokens are the basic buildings blocks in C language which are constructed together to write a Cprogram.  Each and every smallest individual units in a C program are known as C tokens. C tokens example program: int main() main – keyword { {,}, (,) – delimiter int x, y, total; keyword x, y, total – identifier x = 10, y = 20; total = x + y; printf ("Total = %d n", total); main, {, }, (, ), int, x, y, total – tokens } C tokens are of six types. They are, 1. Keywords 2. Identifiers 3. Constants 4. Strings 5. Special charaters 6. Operators Keywords in C language:  Keywords are pre-defined words in a C compiler.  Each keyword is meant to perform a specific function in a C program.  Since keywords are referred names for compiler, they can’t be used as variable name. C language supports 32 keywords which are given below. auto else long switch break enum register typedef case extern return union char float short unsigned const for signed void continue goto sizeof volatile default if static while
  • 2. do int struct _Packed double 2. Identifiers in C language:  Each program elements in a C program are given a name called identifiers.  Names given to identify Variables, functions and arrays are examples for identifiers. eg. x is a namegiven to integer variable in above program. Rules for constructing identifier name in C: 1. First character should be an alphabet or underscore. 2. Succeeding characters might be digits or letter. 3. Punctuation and special characters aren’t allowed except underscore. Identifiers should not be keywords. 3. C constants C Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined.  Constants refer to fixed values. They are also called as literals  Constants may be belonging to any of the data type.  Syntax: const data_type variable_name = value; (or) #define variable_name value Types of C constant: 1. Integer constants 2. Real or Floating point constants 3. Octal & Hexadecimal constants 4. Character constants 5. String constants 6. Backslash character constants Constant type data type (Example) Integer constants int (53, 762, -478 etc ) unsigned int (5000u, 1000U etc)long int, long long int (483,647 2,147,483,680) Real or Floating point constants float (10.456789) doule (600.123456789) Octal constant int (Example: 013 /*starts with 0 */) Hexadecimal constant int (Example: 0x90 /*starts with 0x*/) character constants char (Example: ‘A’, ‘B’, ‘C’) string constants char (Example: “ABCD”, “Hai”) Rules for constructing C constant: 1. Integer Constants in C:  An integer constant must have at least one digit.  It must not have a decimal point.  It can either be positive or negative.  No commas or blanks are allowed within an integer constant.  If no sign precedes an integer constant, it is assumed to be positive.  The allowable range for integer constants is -32768 to 32767.
  • 3. 2. Real constants in C:  A real constant must have at least one digit  It must have a decimal point  It could be either positive or negative  If no sign precedes an integer constant, it is assumed to be positive.  No commas or blanks are allowed within a real constant. 3. Character and string constants in C:  A character constant is a single alphabet, a single digit or a single special symbol enclosed withinsingle quotes.  The maximum length of a character constant is 1 character.  String constants are enclosed within double quotes. 4. Backslash Character Constants in C:  There are some characters which have special meaning in C language.  They should be preceded by backslash symbol to make use of special function of them.  Given below is the list of special characters and their purpose. Backslash character Meaning b Backspace f Form feed n New line r Carriage return t Horizontal tab ” Double quote ’ Single quote Backslash v Vertical tab a Alert or bell ? Question mark N Octal constant (N is an octal constant) XN Hexadecimal constant (N – hex.dcml cnst) How to use constants in a C program? We can define constants in a C program in the following ways. 1. By “const” keyword 2. By “#define” preprocessor directive Variables:  C variable is a named location in a memory where a program can manipulate the data. This location isused to hold the value of the variable.  The value of the C variable may get change in the program.  C variable might be belonging to any of the data type like int, float, char etc. Rules for naming C variable: 1. Variable name must begin with letter or underscore. 2. Variables are case sensitive 3. They can be constructed with digits, letters. 4. No special symbols are allowed other than underscore. 5. sum, height, _value are some examples for variable name
  • 4. Declaring & initializing C variable:  Variables should be declared in the C program before to use.  Memory space is not allocated for a variable while declaration. It happens only on variable definition.  Variable initialization means assigning a value to the variable. Type Syntax Variable declaration data_type variable_name; Example: int x, y, z; char flat, ch; Variable initialization data_type variable_name = value; Example: int x = 50, y = 30; char flag = ‘x’, ch=’l’; Key Differences between Identifier and Variable: 1. Both an identifier and a variable are the names allotted by users to a particular entity in a program. The identifier is only used to identify an entity uniquely in a program at the time of execution whereas, a variable is a name given to a memory location, that is used to hold a value. 2. Variable is only a kind of identifier, other kinds of identifiers are function names, class names, structure names, etc. So it can be said that all variables are identifiers whereas, vice versa is not true. As identifier and variable names are user-defined names, it should be taken care that no two identifiers or no two variable names in a program should be the same. It will create a problem of ambiguity in a program. TOPIC 4: DATA TYPES Data types in c refer to an extensive system used for declaring variables or functions of different types. The typeof a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. The types in C can be classified as follows – Integer Types The following table provides the details of standard integer types with their storage sizes and valueranges −
  • 5. Type Storage size Value range char 1 byte -128 to 127 or 0 to 255 unsigned char 1 byte 0 to 255 signed char 1 byte -128 to 127 int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 short 2 bytes -32,768 to 32,767 unsigned short 2 bytes 0 to 65,535 long 4 bytes -2,147,483,648 to 2,147,483,647 unsigned long 4 bytes 0 to 4,294,967,295 To get the exact size of a type or a variable on a particular platform, you can use the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in bytes. Floating-Point Types The following table provide the details of standard floating-point types with storage sizes and value rangesand their precision − Type Storage size Value range Precision float 4 byte 1.2E-38 to 3.4E+38 6 decimal places double 8 byte 2.3E-308 to 1.7E+308 15 decimal places long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places TOPIC 5: OPERATORS Operators in C Language: C language supports a rich set of built-in operators. An operator is a symbol that tells the compiler to performcertain mathematical or logical manipulations. Operators are used in program to manipulate data and variables. C operators can be classified into following types,  Arithmetic operators  Relational operators  Logical operators  Bitwise operators  Assignment operators  Conditional operators (ternary operator)  Special operators (sizeof (), comma) Arithmetic operators C supports all the basic arithmetic operators. The following table shows all the basic arithmetic operators.
  • 6. Ope rato r Description Synta x E x + adds two operands Operand + operand A+B 4+2 - subtract second operands from first Operand - operand A-B 4+2 * multiply two operand Operand * operand A*B 4+2 / divide numerator by denominator Operand / operand A/B 4+2 % remainder of division Operand % operand A%B 4+2 ++ Increment operator increases integer value byone operand++, ++operand A++ ++A 4+2 -- Decrement operator decreases integer valueby one Operand-- --operand A-- --A 4+2 Program: #include<stdio.h> #include<conio.h> Void main() { int a,b,c,d,e,f,g; printf(“enter a,b:”); scanf(“%d%d”,&a,&b); c=a+b; printf(“sum of a and b is %d”,c); d=a-b; printf(“sbtraction of a and b is %d”,d); e=a*b; printf(“multiplication of a and b is %d”,e); f=a/b; printf(“division of a and b is %d”,f); g=a%b; printf(“modulo of a and b is %d”,g); } Relation operators Relation operators are used to specify the relation between two operands such as greater than, less than, equalto and etc. If the relation between two operands is true then the result is one (1) otherwise zero(0). Assume variable A holds 10 and variable B holds 20 then Operato r Description Example Outp ut == Check if two operand are equal A==B Is not true gives 0 as output != Check if two operand are notequal. A!=B Is true gives 1 as output
  • 7. > Check if operand on the left is greater than operand on the right A>B Is not true gives 0 as output < Check operand on the left issmaller than right operand A<B Is true gives 1 as output >= check left operand is greater thanor equal to right operand A>=B Is not true gives 0 as output <= Check if operand on left is smaller than or equal to rightoperand A<=B Is true gives 1 as output Program: #include<stdio.h> #include<conio.h> Void main() { int a,b,; printf(“enter a,b:”); scanf(“%d%d”,&a,&b); printf(“result for greater than relation operator when its true %d”, a>b); printf(“result for less than relation operator when its true %d”, a<b); printf(“result for greater than or equal relation operator when its true %d”, a>=b); printf(“result for less than or equal relation operator when its true %d”, a<=b); printf(“result for equal relation operator when its true %d”, a==b); printf(“result for not equal relation operator when its true %d”, a!=b); } Logical operators Logical operators are used to perform operations on more than one expression. C language supports following 3 logical operators. Suppose a=1 and b=0, Operator Descripti on Example && Logical AND:Called Logical AND operator. If both the operands are non-zero, then the condition becomes true. (a && b) isfalse || Logical OR: Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (a || b) is true ! Logical NOT:Called Logical NOT Operator. It is used to reverse the logicalstate of its operand. If a condition is true, then Logical NOT operator will make it false. (!a) is false Program: #include<stdio.h> #include<conio.h> Void main() { int a,b,c,d,e;
  • 8. printf(“enter a,b:”); scanf(“%d%d”,&a,&b); c=a&&b; d=a||b ;e=!a; printf(“result for logical and is %d”,c); printf(“result for logical or is %d”,d); printf(“result for logical not is %d”,e); } Bitwise operators: Bitwiseoperators perform manipulations of data at bit level. These operators also perform shifting of bits fromright to left. Bitwise operators are not applied to float or double. Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is as follows – Assume variable 'A' holds 60 and variable 'B' holds 13, then – Operator Descripti on Example & Bitwise AND:Operator copies a bit to the result if it exists in both operands. (A & B) = 12, i.e., 0000 1100 | Bitwise OR: Operator copies a bit if it exists in either operand. (A | B) = 61, i.e.,0011 1101 ^ Bitwise exclusive OR: Operator copies the bit if it is set in one operand butnot both. (A ^ B) = 49, i.e., 0011 0001 ~ Binary Ones Complement Operator is unary and has the effect of 'flipping'bits. (~A ) = -61, i.e,.1100 0011 in 2's compleme ntform << Binary Left Shift:The left operands value is moved left by the number ofbits specified by the right operand. A << 2 = 240 i.e., 1111 0000 >> Binary Right Shift: The left operands value is moved right by the number ofbits specified by the right operand. A >> 2 = 15 i.e., 0000 1111 Now let’s see truth table for bitwise &, | and ^ a b a & b a | b a ^ b 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 The bitwise shift operators shifts the bit value. The left operand specifies the value to be
  • 9. shifted and the rightoperand specifies the number of positions that the bits in the value are to be shifted. Both operands have the same precedence. Example: Assume A = 60 and B = 13 in binary format, they will be as follows −A = 0011 1100 B = 0000 1101 A&B = 0000 1100 A|B = 0011 1101 A^B = 0011 0001 ~A = 1100 0011 Program #include<stdio.h> #include<conio.h> Void main() { int a,b,c,d,e,f,g; printf(“enter a,b:”); scanf(“%d%d”,&a,&b); c=a&b; d=a|b; e=a^b; f=a<<4; g=b>>3; printf(“result for bitwise and is %d”,c);printf(“result for bitwise or is %d”,d); printf(“result for bitwise not is %d”,e);printf(“result for left shift is %d”,f); printf(“result for right shift is %d”,g); } Assignment Operators we explored how results are displayed and how numerical data are stored and processed using variables andassignment statements. Assignment operator (=) is used for assignment a value to a variable and for performing computations.Assignment statement has the syntax: variable = expression; Expression is any combination of constants, variables, and function calls that can be evaluated to yield a result. Example: length = 25; cMyCar = “Mercedes”; sum = 3 + 7;
  • 10. newtotal = 18.3*amount; slope = (y2 – y1)/(x2 – x1); Assignment operators supported by C language are as follows. Operato r Descripti on Examp le = assigns values from right side operands to left side operand a=b, c=a+b += adds right operand to the left operand and assign the result to left a+=b is same as a=a+b -= subtracts right operand from the left operand and assign the result toleft operand a-=b is same as a=a-b *= mutiply left operand with the right operand and assign the result toleft operand a*=b is same as a=a*b /= divides left operand with the right operand and assign the result toleft operand a/=b is same as a=a/b %= calculate modulus using two operands and assign the result to leftoperand a%=b is same as a=a%b <<= Left shift AND assignment operator. C <<= 2 is same as C = C << 2 >>= Right shift AND assignment operator. C >>= 2 is same as C = C >> 2 &= Bitwise AND assignment operator. C &= 2 is same as C = C &2 ^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C = C ^2 |= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C | 2 Program: #include<stdio. h> #include<conio .h> Void main() { int a,b,c,d,e,f,g; printf(“enter a,b:”); scanf(“%d%d”,&a,& b);c+=b; d- =a; e*=b ;
  • 11. a/=2; printf(“result for assignment operator is %d”,c); printf(“result for assignment operator is %d”,d); printf(“result for assignment operator is %d”,e); printf(“result for assignment operator is %d”,a); } Special operators Operato r Description Examp le sizeof Returns the size of an variable sizeof(x) return size of the variable x & Returns the address of an variable &x ; return address of the variable x * Pointer to a variable *x ; will be pointer to a variable x Comma Separate variables, expressions Int a,b,c; Conditional operator It is also known as ternary operator and used to evaluate conditional expression. Conditional operator returns one value when condition is true otherwise returns other value. If condexpr is true ? Then the value isstatement 1 : Otherwise value statement 2. Program: #include<stdio. h> #include<conio .h> Void main() { int a,b,c,d,e,f,g; printf(“enter a,b:”); scanf(“%d%d”,&a,&b); c=(a>b)?a:b; printf(“result for conditional operator is %d”,c); } Conditional expression ? statement1 : statement2
  • 12. 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 ++.
  • 13. Different Types of Increment Operation In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment Operator. A. Pre Increment Operator Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression. 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. Sample program Output : Value of a : 11Value of x: 11 B. Post Increment Operator Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented. 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. Sample program #include<stdio.h> void main() { int a,x=10; a = ++x; printf("Value of a : %d",a); printf("Value of x : %d",x); } #include<stdio.h> void main() { inta,b,x=10; a = x++; printf("Value of a : %d",a); printf("Value of a : %d",x); }
  • 15. Value of a : 10Value of x : 11 Decrement Operator in C Programming : 1. Decrement operator is used to decrease the current value of variable by subtracting integer 1. 2. Like Increment operator, decrement operator can be applied to only variables. 3. Decrement operator is denoted by –. Different Types of Decrement Operation : When decrement operator used in C Programming then it can be used as pre-decrement or post-decrementoperator. A. Pre Decrement Operator Pre-decrement operator is used to decrement the value of variable before using in the expression. In the Pre-decrement value is first decremented and then used inside the expression. b = --var; Suppose the value of variable var is 10 then we can say that value of variable ‘var’ is firstly decremented thenupdated value will be used in the expression. C Program Output : Value of a : 9Value of y : 9 B. Post Decrement Operator Post-decrement operator is used to decrement the value of variable immediatly after executing expression completely in which post decrement is used. In the Post-decrement old value is first used in a expression andthen old value will be decrement by 1. b = var--; #include<stdio.h> void main() { intb,y=10; b = --y; printf("Value of b : %d",b); printf("Value of y : %d",y); }
  • 16. Value of variable ‘var’ is 5. Same value will be used in expression and after execution of expression new valuewill be 4.
  • 17. C Program Output : Value of a : 10Value of x : 9 Operator precedence and associativity: Symbol (4M) Type of Operation (2M) Associativity(2M) [ ] ( ) . –> postfix ++ and postfix –– Expression Left to right prefix ++ and prefix –– sizeof & * + – ~ ! Unary Right to left typecasts Unary Right to left * / % Multiplicative Left to right + – Additive Left to right << >> Bitwise shift Left to right < > <= >= Relational Left to right == != Equality Left to right & Bitwise-AND Left to right ^ Bitwise-exclusive-OR Left to right | Bitwise-inclusive-OR Left to right && Logical-AND Left to right || Logical-OR Left to right #include<stdio.h> void main() { inta,x=10; a = x--; printf("Value of a : %d",a); printf("Value of x : %d",x); }
  • 18. ? : Conditional- expression Right to left = *= /= %= += –= <<= >>= &= ^= |= Simple and compound assignment Right to left , Sequential evaluation Left to right TOPIC 8: EXPRESSION TYPES C Programming Expression: 1. In programming, an expression is any legal combination of symbols that represents a value. 2. C Programming provides its own rules of Expression, whether it is legal expression or illegalexpression. For example, in the C language x+5 is a legal expression. 3. Every expression consists of at least one operand and can have one or more operators. 4. Operands are values and Operators are symbols that represent particular actions. Valid C Programming Expression: C Programming code gets compiled firstly before execution. In the different phases of compiler, c programmingexpression is checked for its validity. Expressions Validit y a + b Expression is valid since it contain + operator which is binary operator + + a + b Invalid Expression Priority and Expression: In order to solve any expression we should have knowledge of C Programming Operators and their priorities. Types of Expression:
  • 19. In Programming, different verities of expressions are given to the compiler. Expressions can be classified on thebasis of Position of Operators in an expression –
  • 20. Type Explanati on Example Infix Expression in which Operator is in between Operands a + b Prefix Expression in which Operator is written before Operands + a b Postfix Expression in which Operator is written after Operands a b + Type ConversionsType casting is a way to convert a variable from one data type to another data type. For example, if you want to store a long value into a simple integer then you can type cast long to int. You can convert values from one type to another explicitly using the cast operator. New data type should be mentionedbefore the variable name or value in brackets which to be typecast. There are two types of type casting in c language. 1. Implicit conversion:  Implicit conversions do not required any operator for converted. They are automatically performedwhen a value is copied to a compatible type in program.  Here, the value of a has been promoted from int to double and we have not had to specify any type-casting operator. This is known as a standard conversion. Program: #include<stdio.h> #include<conio.h> Void main() { int i; float f; double d; long int l; x=l/i+i*f-d; printf(“%d”,x); }
  • 21. 2. Explicit conversion In c language, many conversions, especially those that imply a different interpretation of the value, require anexplicit conversion. We have already seen two notations for explicit type conversion. Syntax: (data type) expression; They are not automatically performed when a value is copied to a compatible type in program. Program: #include<stdio. h> #include<conio .h> Void main() { int n; float sum=0; for(n=1;n<=10;n ++) sum=sum+1/float (n);printf(“ %f”,sum); } } In the above example, n declares as integer after that its converted into float so the result also bein float data type only. TOPIC 9: FLOW OF CONTROL Control Flow-Relational Expressions - Logical Operators Control Structures are those statements that decide the order in which individual statements or instructions of aprogram are executed or evaluated. Control Structures are broadly classified into: 1. Conditional statements: Specifies a condition to execute a group of statements in a program.The control structures, if, if-else, nested if, if else ladder and switch, belongs to this category. 2. Iterative statements: Executes one or more statements repeatedly until a condition is met.The control structures: while, do...while, and for loops, belong to this category. 3. Jump statements: Transfer of control from one part to another within the program. Ex. goto,break, continue and return. Selection: if-else Statement, nested if Single way selection (Simple if statement) The if statements executes a simple or compound statements, depending on whether or not an expression is trueof false. The syntax if(conditional expression) statements; // single statement if(conditional expression) {
  • 22. //compound statements statement 1; statement 1; statement 1; } The flow chart for the single-way decision logic is shown.
  • 23. In the preceding syntaxes, a simple or compound statement (block of statements) is executed when the condition expression is true. Otherwise, the program control passes to next statement. If the condition expression is false then the C compiler does not do anything. Note that the condition expression given in parenthesis, must be evaluated as true (non-zero value) or false (zerovalues). In addition, a compound statement must be provided by opening and closing braces. Examples: if(7) // a non zero value returns true if(0) //zero value returns false if(i==0) //True if i=0 other wise False if(i=0) //false because value of the expression is zero Program: #include<stdio .h>main() { int a,b,c,d; float ratio; printf(“enter a,b,c,d values ”); scanf(“%d%d%d%d”,&a,&b,& c,&d);if(c-d!=0) { ratio=(float)(a+b)/(float) (c-d);printf(“the ratio is %f”,ratio); } Output: Enter a,b,c,d values 11 12 7 5The ratio is 11.500000 Two - way selection (if-else statement) The basic decision statement in the computer is the two-way selection. If the condition is true, one or moreaction statements are executed. If the condition is false, then a different action or set of actions is executed. Syntax: if(conditional-expression) { } els e { } true-block statements; false-block Statements;
  • 24. The flow chart for the two-way decision logic is shown.
  • 25. Example: write a C code to find biggest of two numbers using if-else statement #include<stdio .h>void main() { int a,b; printf(“enter two values”); scanf(“%d%d”,&a,& b); if(a>b) { } els e { } } printf(“%d is Big Value”,a); printf(“%d is Big Value”,b); Null else, nested if, examples Null Else: if else statement does not have any executable statements then it is consider as null else statement. Soelse part will contain only (;) because it doesn’t have any executable statements. The syntax is as follows: if(test-condition) { true-block statements; } else; Example: if(sal>10000) { sal=sal+1000; } else; Nested if statement When an if-else is included within an if-else, it is known as a nested if statement. The control of a programmoves into the inner if statements when the outer if statement is evaluated to be true. Include one condition within another condition is known as nested if.
  • 26. Syntax of nested if statement: if (test expression1) { if(test expression2) {
  • 27. Statement-1; } else { Statement-2; } els e { } if(text expression-3) { statement-3; } else { statement-4; } } Flowchar t: . Example of nested if statement : write C code to find the biggest of three number #include<stdio .h>Void main() { int a,b; printf(“enter three values”); scanf(“%d%d%d”,&a,&b,&c); if(a>b) { if(a>c) printf(“Biggest Number=%d”,a);else printf(“Biggest number=%d”,c); } else { if(b>c) printf(“Biggest Number=%d”,b);
  • 28. else printf(“Biggest number=%d”,c); } } Example: #include<stdio .h>main() { int password; char username; printf(“enter user name”); scanf(“%c”,&userna me); printf(“enter password”); scanf(“%d”,&passwo rd); if(username==’a’) { If(password==123) printf(“login sucessfull”); } els e els e printf(“Invalid password”); printf(“invalid user name”); } Example programs on simple if and if-else statementsProgram: #include<stdio .h>main() { int a,b,c,d; float ratio; printf(“enter a,b,c,d values ”); scanf(“%d%d%d%d”,&a,&b,&
  • 30. example: write a C code to find biggest of two numbers using if- else statement#include<stdio.h> void main() { int a,b; printf(“enter two values”); scanf(“%d%d”,&a,& b); if(a>b) { } els e { } } printf(“%d is Big Value”,a); printf(“%d is Big Value”,b); Example programs on nested if Example of nested if statement : write C code to find the biggest of three number#include<stdio.h> Void main() { int a,b; printf(“enter three values”); scanf(“%d%d%d”,&a,&b,&c); if(a>b) { if(a>c) printf(“Biggest Number=%d”,a);else printf(“Biggest number=%d”,c); } else { if(b>c) printf(“Biggest Number=%d”,b);else printf(“Biggest number=%d”,c); } } Example: #include<stdio .h>main() { int password; char username; printf(“enter user name”); scanf(“%c”,&userna me); printf(“enter
  • 32. } els e printf(“Invalid password”); printf(“invalid user name”); } Multi-way selection: switch, else-if,The switch statement  The switch statement can be used to make multi-way decisions  It is especially good when you have many cases to choose from  There are still situations where you do have to use if statements, however The Syntax of switch switch (expression) { case (expression) : Statements; break; case (expression): Statements; break; // more cases can go here default: Statements; } The following rules apply to a switch statement −  The expression used in a switch statement must have an integral or enumerated type, or be of a classtype in which the class has a single conversion function to an integral or enumerated type.  You can have any number of case statements within a switch. Each case is followed by the value to becompared to and a colon.  The constant-expression for a case must be the same data type as the variable in the switch, and itmust be a constant or a literal.  When the variable being switched on is equal to a case, the statements following that case will executeuntil a break statement is reached.  When a break statement is reached, the switch terminates, and the flow of control jumps to the nextline following the switch statement.  Not every case needs to contain a break. If no break appears, the flow of control will fall through tosubsequent cases until a break is reached.  A switch statement can have an optional default case, which must appear at the end of the switch. Thedefault case can be used for performing a task when none of the cases is true. No break is needed in the default case. Flow Diagram
  • 33. Else-if ladder Statement An if statement can be followed by an optional else if...else statement, which is very useful to test variousconditions using single if...else if statement. When using if...else if..else statements, there are few points to keep in mind −  An if can have zero or one else's and it must come after any else if's.  An if can have zero to many else if's and they must come before the else.  Once an else if succeeds, none of the remaining else if's or else's will be tested. Syntax The syntax of an if...else if...else statement in C programming language is −if(expression 1) { Statement 1; } else if(expression 2) { Statement 2; } else if(expression 3)
  • 35. Flowchart: Programs on switch caseExample #include<stdio. h> #include<conio .h> #include<math. h> void main() { Int a,b,c,ch; clrscr(); printf("nenter value of a and b:");scanf("%d %d",&a,&b); printf("nlist:n1.Additionn2.Subtractionn3.Multiplicationn 4.Modulus");printf("nEnteryour choice:"); scanf("%d",&ch); switch(ch) { case 1: c=a+b; brea k;case2: c=a-b; brea k;case 3: c=a*b; brea k;case 4: c=a/b; break; default: printf("wrong option");break;
  • 36. } printf("nResult of %d and %d is %d",a,b,c);getch(); }
  • 37. Example programs on else if ladderExample #include <stdio.h>void main () { int a = 100; if( a == 10 ) { printf("Value of a is 10n" ); } else if( a == 20 ) { printf("Value of a is 20n" ); } else if( a == 30 ) { printf("Value of a is 30n" ); } else { printf("None of the values is matchingn" ); } printf("Exact value of a is: %dn", a ); } Example: #include<stdio .h>main() { int marks; printf(“enter your marks”); scanf(“%d”,&marks); if(marks>=90) printf(“YOUR GRADE :An”);else if(marks>=70 && marks<90) printf(“YOUR GRADE: Bn”);else if(marks>=50 && marks<70) printf(“YOUR GRADE:Cn”); else } printf(“YOUR GRADE: FAILEDn”);