28.3k views
4 votes
What are the purpose of each in c++?

if statements?
switch statements?
multiway if?
nested loops?
rand?
srand?
seed?

User Kensuke
by
5.0k points

1 Answer

6 votes

If statements- This statement is used to check the condition.

if(condition)

{

statement

}

If the condition is true,then statement will run,else not.

Switch statement-This statement is used for long conditions.It is a substitute for if,else conditions

switch(a)

{

case1: statement 1//if a=1

break;

case2: statement 2 //if a=2

break;

.....

default:statement//if a is not equal to any of the cases.

Multiway if-In this statement ,if elseif and else were there.

if(condition1)

{

statement 1

}

elseif(condition2)

{

statement 2

}

..............

else

{

statement n

}

Nested loops-This statements are used when we use if-else conditions in other if,else conditions.

if(condition 1)

{

if(condition 2)

{

if (condition 3)

{

statement 3

}

else

{

statement 4

}

}

]

rand()-This method is used for generating random number.The expression is

number=rand()%50;

It will generate a random number ranges between 0 to 50.

srand()-This method is used to set the starting value for random number series.

srand (time(NULL));

seed()-It is a method for initializing the same random series,it is passed in srand().

User Sayeda
by
6.1k points