Professional Documents
Culture Documents
Control Statements: A Programme. in Other Words, The Control Statements Determine The 'Flow of
Control Statements: A Programme. in Other Words, The Control Statements Determine The 'Flow of
Control Statements has the ability to change the sequential order of execution in
a programme. In other words, the control statements determine the 'flow of
Control' in a program. Control statements are of following types:
syntax:
if (expression)
{
if (expression) S1; if (expression)
Block S2; S1;
next statements; $3; next statements
}
next statements
The expression can be any type of statement returning integer value not a
Ifthe result of expression is non zero (treated as true), then execution continues
from first statement of the Block.
If the result is zero (treated as false) then control of execution is transfered to
next statements to the Block. Statement(s) in the block are not executed.
Relational & Equality Operator
X X IS equal to y
xy X 1S greater than y
xy x is less than equal to y
or
#include <stdio.h>
int main0
variable declaration
Computation:
Give grace mark 40 to everyone 40 mark grace to all
Test the age
if (age <
50) 20 mark more grace if age is below 50
marks =marks + 20;
Display Result
WAP to give 60 mark grace if age is below 50 else give 40 marks grace
i.e. all will get atleast 40mark grace additional 20 mark will be given if the age is
below 50.
14
#include <stdio.h>
int main0
Display Result
WAP to print KIIT student if you are in class 1 to 12 else print
KIIT University student.
23
#include <stdio.h>
int main0
{
int clasS //variable declaration
printf("Enter Class:");
scanf("%d', &class); /value assigning
#include <stdio.h> b
int main0
O
float P,Q R, S; //variable declaration
assign the values to PQR,Susing scanfO0: O
if(P*S==R *Q) R
a=30
c-20
Step-2: Compare value of max with 2nd (b) number and store largest among them
in max
Step-3: Compare value of max with 3rd (c) number and store largest among them
in max
Write a program to print the largest among three numbers (a, b, c)
42
#include <stdio.h>
int main(0 a-30
#include <stdio.h>
int main0 a-30
int a, b, C, max:
printf\nEnter 3 numbers"); max-50 b-50
scanf("%d %d %d", &a, &b, &c);
max-a;
c-20
iffb>max)
max-b;
if(c>max)
max-c;
printf("\nThe largest No. is %d'", max);
return(0);
Find the output
int a-0;
if (a<1) if (a>1)
L1: printf(" XXX"); //Block L1: printf(" 000"); //Block
L2: printf(" YYY"); L2: printf(" 1111");
if (1) if (a)
L1: printf(" KiIT"); L1: printf(" KIIT"):
L2: printf(" University"); L2: printf(" University");
if (a=1) if (a=a++)
L1: printf" Comp. Sc."): L1: printf(" Comp. Sc.");
L2: printf(" Engineering"); L2: printf" Engineering');