हिंदी माध्यम नोट्स
Multiple Control Variable , Nesting of for loops , Elimination , for loop As time delay in hindi
1. Multiple Control Variable :
looping मे प्रोग्रामर multiple control variable को initial करके उससे control statement बना सकता है |लेकिन ये सुविधा for loop मे ही होती है |for loop मे एक या एक अधिक control variables को आसानी से use किया जा सकता है | उदहारण के लिए :#include <conio.h>
#include<stdio.hj>
void main()
{
int sum=50 ;
int variable 1, variable 2;
for (variable 1=1,variable 2=12;variable !=variable 2;variable++,variable 2–)
{
sum=sum+1;
printf(“Sum is = %d\n”,sum);
}
}
इस उदहारण मे , दो control variables named variable 1 और variable 2 है|
1.दोनों को for loop मे initial किया गया है |
2.फिर variable 1 इस not equal variable 2 को check करता है |
3.variable 1 को increment और variable 2 को decrement किया जाता है |
आउटपुट होगा :
Sum is=51
Sum is=52
Sum is=53
Sum is=54
Sum is=55
Sum is=56
Sum is=57
2. Nesting of for loops:
for loop मे nesting possible है |Nesting का मतलब है एक for loop के executable block मे दुसरे loop को चलाया जा सकता है |इसका syntax है :-
for (i=1;i<10;i++)
{
for(j=1;j<10;j++)
{
statement block ;
}
}
Nesting ऑफ़ for loop के कारण for loop तीनो loops (while,do-while,for) मे से सबसे ज्यादा use किया जाता है |दोनों for loop के लिए ,दो अलग अलग control variable होने चाहिए| इसका उदहारण है :-
#include <conio.h>
#include<stdio.h>
void main()
{
int sum=50 ;
int i,j;
for(i=2;i<=4;i++)
{
printf(“table of %d \n”,i);
for (j=1;j<=10;j++)
{
int mul=0;
mul=i*j;
printf(“%d”,mul);
}
}
}
इस उदहारण मे , 2 और 3 का table print होगा | i की value =2 डिजिट जिसका table print करना है तब j की value 1 से 10 की बढती रहती है |जब j की value 10 पर पहुच जाती है तब control outer loop पर चला जाता है | i की value 3 हो जाती |पूरी प्रोसेस दोबारा होती |
आउटपुट होगा |
table of 2
2468101214161820
table of 3
36912151821242730
3. Elimination:
Elimination का अर्थ है की for loop मे सभी initial ,condition और increment होना जरुरी नहीं है|उदहारण के लिए :-
#include<conio.h>
#include<stdio.h>
void main()
{
int i=1;
for (; i<5;)
{
printf(“value of i=%d\n”,i);
i++;
}
getch();
}
इस उदहारण मे initial और increment statement for loop मे नहीं है | बल्कि initial variable initial मे और increment loop की execuable body मे है |
आउटपुट होगा :
value of i=1
value of i=2
value of i=3
value of i=4
4. for loop As time delay
किसी प्रोग्राम के executable time को बढ़ने के लिए for loop को use किया जा सकता है |इसके लिए loop के body पार्ट मे केवल semicolon (;) को introduce करना होता है |
उदहारण के लिए :
#include<conio.h>
#include<stdio.h>
void main()
{
char name ;
printf(“Enter your name”);
scanf(“%s”,&name);
int i=1;
for (i=1;i<1000;i++)
{
;
}
printf(“your name is %s .”, name);
getch();
}
इस उदहारण मे , जब तक for loop 1000 times run नहीं होगा तब तक your name is %s print नहीं होगा |
आउटपुट होगा :
Enter your name Parth
your name is Parth .
5. Break Statement in for loop :
for loop को terminate मे करने के लिए break statement को use किया जाता है |break statement तीनो loop मे इस्तेमाल हो सकता है |इसका syntax है :-
while(condition-1)
{
statement-1;
if(condition-2)
break;
statement-2;
initial;
}
और
do
{
statement 1;
if(condition-2)
break;
statement-2;
}
while(condition-1)
और
for (initial;condition-1;increment)
{
statement-1;
if(condition-2)
break;
statement-2;
}
उदहारण के लिए :
3include<conio.h>
#include<stdio.h>
vopid main ()
{
int i;
int a=89,b=90;
int sum;
for(i=1;i<10;i++)
{
sum=a+b;
if(Sum>500)
break;
printf(“Your sum is =%d\n “,sum);
a=a+50;
b=b+50;
}
printf(“sum is bigger than 500.”);
}
आउटपुट होगा :
Your sum is=179
Your sum is=279
Your sum is=379
Your sum is=479
sum is bigger than 500.
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…