https://www.rakeshmgs.in/search/label/Template
https://www.rakeshmgs.in
RakeshMgs

Decision Making in Programming C | Using if else, if, else if, else statement

Updated:

 

Decision making in C

เค†เคช เค…เคชเคจे program เคฎें เค•ौเคจเคธे statements เค•ो execute เค•เคฐเคจा เคšाเคนเคคे เคนै เค”เคฐ เค•ौเคจเคธे statements เค•ो skip เค•เคฐเคจा เคšाเคนเคคे เคนै เคฏे เค†เคช เค–ुเคฆ decide เค•เคฐ เคธเค•เคคे เคนै। เค‡เคธे decision making เค•เคนเคคे เคนै। เคœ्เคฏाเคฆाเคคเคฐ decision making เค•िเคธी condition เค•े base เคชเคฐ เค•ी เคœाเคคी เคนै।

เคเค• particular condition เค†เคจे เคชเคฐ เค†เคช เคฎเคจเคšाเคนे statements เค•ो execute เค•เคฐ เคธเค•เคคे เคนै। เค‡เคธเค•े เคฒिเค เค†เคช เค•ुเค› built in statements เค•ो เคฏूเคœ़ เค•เคฐเคคे เคนै। เค•्เคฏोंเค•ि เคฏे statements conditions เค•े เคธाเคฅ เค•ाเคฎ เค•เคฐเคคे เคนै เค‡เคธเคฒिเค เค‡เคจ्เคนें conditional statement เคญी เค•เคนा เคœाเคคा เคนै।
เค”เคฐ เค•्เคฏोंเค•ि เคฏे statement program เคฎें execution เค•ो control เค•เคฐเคคे เคนै เค‡เคธเคฒिเค เค‡เคจ्เคนें control statements เคญी เค•เคนा เคœाเคคा เคนै।

1. if statement
2.switch statement
3.conditional operator statement (? : operator)
4.goto statement

Decision making with if statement

1.Simple if statement
2.if....else statement
3.Nested if....else statement
4.Using else if statement

Simple if statement

	
	
if(expression) { statement inside; } statement outside;

If statement curly braces {} เค•े เคฆ्เคตाเคฐा เคเค• block define เค•เคฐเคคा เคนै। เคœเคฌ condition true เคนोเคคी เคนै เคคो เค‡เคธ block เคฎें เคฆिเค เค—เค statement execute เคนोเคคे เคนै।

เคฏเคฆि condition false เคนो เคคो เค‡เคธ เคชुเคฐे block เค•ो compiler skip เค•เคฐ เคฆेเคคा เคนै। เคฏเคฆि เค‰เคชเคฐ เคฆिเค เค—เค example เคฎें if statement เค•ा use เค•िเคฏा เคœाเคฏे เคคो program เค•ो เค‡เคธ เคช्เคฐเค•ाเคฐ เคฒिเค–ा เคœा เคธเค•เคคा เคนै।

if...else statement

If else statement เค•ो if statement เค•ा เคนी part เคฎाเคจा เคœाเคคा เคนै। เคฒेเค•िเคจ เค‡เคธเคฎें else block เค”เคฐ add เค•िเคฏा เคœाเคคा เคนै। Else block เคฎें เคฆिเค เค—เค statement เคคเคฌ execute เคนोเคคे เคนै เคœเคฌ if เค•ी condition false เคนो เคœाเคคी เคนै।

เคœैเคธा เค•ी เค†เคชเค•ो เคชเคคा เคนै if เค•ी condition true เคนोเคจे เคชเคฐ if block เคฎें เคฆिเค เค—เค statements execute เคนोเคคे เคนै। เคฒेเค•िเคจ เค†เคช เคฏे เคญी decide เค•เคฐ เคธเค•เคคे เคนै เค•ी เคฏเคฆि condition false เคนो เคคो เค•्เคฏा เค•िเคฏा เคœाเคจा เคšाเคนिเค। เค‡เคธเค•े เคฒिเค เค†เคช else block เคฏूเคœ़ เค•เคฐเคคे เคนै। เคฏे block เคนเคฎेเคถा if block เค•े เคฌाเคฆ เคฎें เค†เคคा เคนै।

	
	
if(expression) { statement block1; } else { statement block2; }

เค‡เคธ block เคฎें เคตो statements เคฒिเค–े เคœाเคคे เคนै เคœो เค•ी condition false เคนोเคจे เคชเคฐ execute เคนोंเค—े। เคฏเคฆि เคŠเคชเคฐ เคฆिเค เค—เค เค‰เคฆाเคนเคฐเคฃ เคฎें if else statement เค•ा เคช्เคฐเคฏोเค— เค•िเคฏा เคœाเคฏे เคคो เค†เคช เค‰เคธे เค‡เคธ เคช्เคฐเค•ाเคฐ เคฒिเค– เคธเค•เคคे เคนै।

	
	
#include <stdio.h> void main( ) { int x, y; x = 15; y = 18; if (x > y ) { printf("x is greater than y"); } else { printf("y is greater than x"); } }

Output

y is greater than x

Nested if....else statement

เคฏเคฆि เค†เคช if เค”เคฐ else เค•े เคฌीเคš เคฎें เคเค• เค”เคฐ condition เคฒเค—ाเคจा เคšाเคนเคคे เคนै เคคो เคเคธा เค†เคช else if block define เค•เคฐเค•े เค•เคฐ เคธเค•เคคे เคนै।

	
	
if(expression) { statement block1; } else if { statement block2; } else { statement block3; }

เคฏเคฆि expression เค—เคฒเคค เคนै, เคคो statement-block3 show เค•िเคฏा เคœाเคเค—ा, เค…เคจ्เคฏเคฅा เคจिเคท्เคชाเคฆเคจ เคœाเคฐी เคฐเคนเคคा เคนै เค”เคฐ เคชเคนเคฒे เค•े เค…ंเคฆเคฐ เคช्เคฐเคตेเคถ เค•เคฐเคคा เคนै เคฏเคฆि เค…เค—เคฒे เค•े เคฒिเค เคšेเค• เคช्เคฐเคฆเคฐ्เคถเคจ เค•เคฐเคจा เคนै เคฏเคฆि statement-block, เคœเคนां เค…เค—เคฐ expression 1 true เคนै, เคคो statement-block 1 executed เคนो เค—เคฏा เคนै เค…เคจ्เคฏเคฅा statement-block 2 executed เคนै|

else if ladder

else-if ladder เคธाเคฎाเคจ्เคฏ เคฐूเคช

	
	
if(expression1) { statement block1; } else if(expression2) { statement block2; } else if(expression3) { statement block3; } else { default statement; }

expression เค•ा test เคŠเคชเคฐ (เคธीเคข़ी เคธे) เคจीเคšे เค•ी เค“เคฐ เคธे เค•िเคฏा เคœाเคคा เคนै। เคœैเคธे เคนी เคเค• true conditon เคฎिเคฒเคคी เคนै, เค‰เคธเคธे เคœुเคก़े statement เค•ो executed เค•िเคฏा เคœाเคคा เคนै।


เค†เคชเค•ो เค†เคฐ्เคŸिเค•เคฒ เค•ैเคธा เคฒเค—ा? เค…เคชเคจी เคฐाเคฏ เค…เคตเคถ्เคฏ เคฆें
Please don't Add spam links,
if you want backlinks from my blog contact me on rakeshmgs.in@gmail.com