Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program.

Similar presentations


Presentation on theme: "A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program."— Presentation transcript:

1 A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program. Test the logical conditions Control the flow of execution as per the selection. These conditions can be placed in the program using decision making statements. C Language too much be able to perform different sets of action depending on the circumstances. The major decision making instructions are listed below. The if statement The if –else statements The if-else-if ladder statements(nested if) The switch ( ) case statements. 1Basic of Computer & 'C' programming

2 1.The if statement:- C uses the keyword if to execute a set of command lines or one command line when the logical condition is true. It has only one option. The set of command lines or command lines are executed only when the logical condition is true. Syntax of if statement if(condition is true) [Note: – No semicolon] statements; 2Basic of Computer & 'C' programming

3 Program using if :- Q. WAP to check whether the candidate age is > than 17 or not. If yes, display message “Eligible for voting”. #include void main() { int age; printf(“ Enter your Age”); scanf(“%d”, &age); if (age>17) printf(“ Eligible For Voting”); } 3Basic of Computer & 'C' programming

4 Q. WAP to check two no are equal. #include void main() { int m,n; printf(“ Enter Two No”); scanf(“%d%d”, &m,&n); if (m-n= =0) printf(“ \nTwo No are Equal”); } 4Basic of Computer & 'C' programming

5 2.The if –else statements:- The if –else statements takes care of true as well as false condition. It has two blocks, one block is for if and it is executed when the condition is true. The other block is of else and it is executed when the condition is false. The else statement cannot be used without if. No multiple else statements are allowed with one if. Syntax of if-else statement if(condition is true) [Note: – No semicolon] execute the statements; else execute the statements; 5Basic of Computer & 'C' programming

6 Programs using if-else :- Q. Read the values of a, b, c through the keyboard. Add them and after addition check if it is in the range of 100 & 200 or not print separate message for each. #include void main() { int a,b,c,d; printf(“ Enter Three No a b c”); scanf(“%d%d%d”, &a,&b,&c); d=a+b+c; if (d =100) printf(“ \nSum is %d which is in between 100 &200”, d); else printf(“\n Sum is %d which is out of range”, d ); } 6Basic of Computer & 'C' programming

7 Q. If his basic salary is less then Rs. 1500, then HRA =10% of basic salary and DA= 90 % of basic salary. If his salary is either equal to or above Rs. 1500 then HRA= Rs. 500 and DA= 98% of salary. Find the Gross Salary. #include void main() { float bs, gs, da, hra; printf(“ Enter Basic Salary”); scanf(“%f”, &bs); if (bs<1500) { hra=bs*10/100; da=bs*90/100; } Else { hra=500; da=bs*98/100; } gs=bs+hra+da; printf(“Gross Salary=Rs %f”, gs ); } 7Basic of Computer & 'C' programming

8 Thanks 8Basic of Computer & 'C' programming


Download ppt "A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program."

Similar presentations


Ads by Google