Switch statement is an extension of if.......else statement. This permits any number of branches. The syntax is
GURU NANAK DEV CO-ED POLYTECHNIC
Friday, 30 September 2011
(iii) Nested if....else statement
This statement is formed by joining if..........else statements either in the if block or in the else block or both. The syntax is
(iii) else.....if statement
else.....if adder statement is used to take multi-way decision. This statement is formed by joining if.......else statements in which each else contains another if......else. The syntax is,
(ii) if....else statement
if........else statement is used to execute one group of statements if the test condition is true or other group if the test condition is false. The syntax is
Decision making statements
Decision making statements are used to skip or to execute a group of statements based on the result of some conditions. The decision making statements are,
(i) Simple if statement
(ii) if.......else statement
(iii) nested if
(iv) switch statement
(i) Simple if statement
The Simple if statement is used to execute or skip one statement or group of statements for a particular condition. The syntax is
if(test condition)
{
statement block;
}
next statement;
When this statement is executed, the computer first evaluates the value of the test condition. If the value is true, statement block and next statement are executed sequentially. If the value is false, statement block is skipped and execution starts from next statement.
Conditions
(i) The opening and closing curl brackets {} are must if the statement block
contains more than one statement.
contains more than one statement.
(ii) The brackets around the test condition are must
(iii) The test condition must be relational or logical expression
(iv) Statement block is called body of the if statement and it contains one or
more statement blocks.
more statement blocks.
#include<stdio.h>
main( )
{
int salary;
char good;
scanf (“%d %c”, &salary,&performance);
if (performance= =‘good’
{
salary=salary+1000;
}
printf(“%d”, salary)’
}
This program tests the performance of an employee. If the performance of an employee in an organization is good, then Rs.1000/- will be added to his salary. For other grades no incentives are added.
C Programming- Assignment Operators
Assignment operators are operators, which are used to simplify the coding of certain type of assignment statement. The syntax is
variable operator = expression
where,
variable - valid user defined name
operator - + - * / %
expression - constant (s)or a variable(s) or operator(s)
Example
The table given below lists the operators with example.
Operator | Meaning |
+= | value of LHS variable will be added to the RHS value and is assigned to LHS variable. |
-= | RHS value will be subtracted from LHS variable and is assigned to LHS variable. |
*= | value of LHS variable will be multiplied by the RHS value and is assigned to LHS variable. |
/= | value of LHS variable will be divided by the RHS value and is assigned to LHS variable. |
%= | value of LHS variable will be divided by RHS value and the remainder will be stored in the LHS variable. |
Wednesday, 14 September 2011
Data Types
Dear students,
I think we are too much concentrating on our practical classes, than that of our theory. Even though, practicals are more important than that of mugging up some text and vomiting it on a piece of paper; we cannot proceed further with programs if we are not convenient in its usage.
Hence, Let us spare time for theoretical discussions also.
Objectives:
In this lesson let us discuss about :
1.declare (name) a local variable as being one of C's five data types
2.initialise local variables
3.perform simple arithemtic using local variables
I think we are too much concentrating on our practical classes, than that of our theory. Even though, practicals are more important than that of mugging up some text and vomiting it on a piece of paper; we cannot proceed further with programs if we are not convenient in its usage.
Hence, Let us spare time for theoretical discussions also.
Objectives:
In this lesson let us discuss about :
1.declare (name) a local variable as being one of C's five data types
2.initialise local variables
3.perform simple arithemtic using local variables
Tuesday, 13 September 2011
HTML Tags / Codes / Web Page Design
|
Subscribe to:
Posts (Atom)