Publicité
Publicité

Contenu connexe

Publicité

control statements.pptx

  1. Control Statements in C Language Presented by Name: K.Abhinay Class : CSM-C
  2. Defination  Are those statements which will depend on condition for their execution. Types of Conditional Statements  If condition  if-else condition  If-else ladder  Nested if-else • if-else condition • Nested if-else • If-else ladder 2/10/2023 PRESENTATION TITLE 2
  3. If statement if(condition) { statement1; .......... } statement x
  4. flowchart 2/10/2023 PRESENTATION TITLE 4
  5. 2/10/2023 PRESENTATION TITLE 5
  6. if evaluates to true. It does nothing when the expression evaluates to false. Else is used when we want some statements to be executed when if evaluates to be false. So if the condition is true, if is executed else , else is executed. 2/10/2023 6 if-else condition
  7. If(condition) { Statement1; Statement2; } else { Statement3; Statement4; } 2/10/2023 PRESENTATION TITLE 7
  8. 2/10/2023 8
  9. Nested if-else • if-else construct within either the body of the if statement or the body of an else statement or both. Thisis called nesting‘ of ifs. 2/10/2023 PRESENTATION TITLE 9
  10. 2/10/2023 PRESENTATION TITLE 10
  11. WAP to find greatest of 3 numbers using nested if-else #include<stdio.h> int main() { int a,b,c; printf(“enter a,b,cn”); scanf(“%d%d%d”,&a,&b,&c); if(a>b) { if(a>c) { printf(“%d is greatest”,a); } 2/10/2023 11 else { printf(“%d is greatest”,c); } }else { if(b>c) { printf(“%d is greatest”,b); }else { printf(“%d is greatest”,c); } } Return 0; }
  12. If-else Ladder • It is used to check multiple conditions. • Every else is associated with its previous if. • The last else goes to work only if all the conditions fail. • Even in else if ladder the last else is optional. 2/10/2023 PRESENTATION TITLE 12
  13. 2/10/2023 PRESENTATION TITLE 13
  14. Thank you
Publicité