Friday, May 17, 2013

if else if

if else if


An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.
Rule of if else if:

  •   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:

[ Note: /*......................*/ is used only for comment ] 

The syntax of an if...else if...else statement in C programming language:

If (expression 1)
{
   /* Executes when the expression 1 is true */
}
else if (expression 2)
{
   /* Executes when the expression 2 is true */
}
else if (expression 3)
{
   /* Executes when the expression 3 is true */
}
else 
{
   /* executes when the none of the above condition is true */
}

What is Prime Number

Prime Number

Prime number is a number which is  divisor by 1 and itself. It is a number that can't divisor except 1 or itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29.
On the other hand, A prime number is a whole number greater than 1, whose only two whole-number factors are 1 and itself..
Suppose n is a whole number, and we want to test it to see if it is prime.   First, we take the square root (or the 1/2 power) of n; then we round this number up to the next highest whole number.  Call the result m.  We must find all of the following quotients:
qm = n / m
q(m-1) = n / (m-1)
q(m-2) = n / (m-2)
q(m-3) = n / (m-3)
. . .
q3 = n / 3
q2 = n / 2
The number n is prime if and only if none of the q's, as derived above, are whole numbers.

if and statement

if and statement

The  if   statement controls conditional branching. The body of an if statement is executed if the value of the expression is nonzero. The syntax for the if statement has two forms.

Syntax
Selection-statement:
if ( expression ) statement
if ( expression ) statement else statement

In both forms of the if statement, the expressions, which can have any value except a structure, are evaluated, including all side effects.

In the first form of the syntax, if expression is true (nonzero), statement is executed. If expression is false, statement is ignored. In the second form of syntax, which uses else, the second statement is executed if expression is false. With both forms, control then passes from the if statement to the next statement in the program unless one of the statements contains a break, continue, or goto.

The following are examples of the if statement: 

if ( i > 0 )
    y = x / i;
else
{
    x = i;
    y = f( x );
}