Decision statements concepts explanation :
Decision statements are classifeied into
simple "If" :
*if statement is powerfull decision making statement
* It is used to control the flow of excution of statement
syntax
if(condition)// dont mention any commas /semicolons
{
printf("star code learns");
}
NOTE:
- It is a basically two way decision statement , one true and another one is false
- It have only one option . our condition either true or false
program :
#include<stdio.h>
#include<conio.h>
main()
{
int A,b;
printf(" enter the values of A & B");
scanf("%d%d",&A&B);
if (A-B)==0)
{
printf("A-B values are equal to zero ");
}
printf("it is false statement");
}
*If else statement :
- it is observe that if statement excuted only when the condition is true it is excuting the if condition
- in if-else either true block or false blolck will be excuted and not both . the else statement cannot be used " without if
if else
#include<stdio.h>
main()
{
printf(" condition true");
}
else
{
printf(" condition false");
}
program:
#include<stdio.h>
main()
{
int a;
printf("enter the value of number");
scanf("%d",&a);
if ((a%2)==0)
{
printf("the given even value");
}
else
{
printf("the given value odd");
}
printf ("thank you");
}
*nested if:
using of one if else statement in another if else statement is called nested if else
when a serial of decision is involved we may have use more than one if else statement in nested form
program
#include<stdio.h>
main()
{
int a,b,c
printf(" enter the value of a,b,c");
scanf("%d%d%d",&a,&b,&c);
printf("the biggest number is ");
if(a>b)
{
if(a>c)
{
printf("%d",%a);
}
else
{
printf("%d",c);
}
else
{
if(b>c)
{
printf("d",b);
}
}
if else ladder:
- switch case: a witch case is another condition or control statement used to select one optoin from several option based on given expresion value , there ius no alternative for"if else ladder"
- switch statement causes a particular group of statement to be hoosen from several available group
- the selection is based upon current value of an expression . ehich include with in the switch statement
- a switch statement is multiple(or) multiway branch statement
program:
#include<stdio.h>
#include<conio.h>
main()
{
int a, b, scl;
printf("enter the values of ab");
scanf("%d%d",&a&b);
}
switch(scl)
{
case: scl=a+b
printf("sum of a+b=%d",a+b);
break;
// like same in subtaction and multiplication and divison ,try it yourself and answer in comment box//
4 Comments
Nic in our study
ReplyDeleteInteresting in studying c language in ur website
ReplyDeleteInteresting studying c language in ur website.
ReplyDeleteI am a beginner for c language
ReplyDeleteIt really helped