हिंदी माध्यम नोट्स
Categories: c++ language in hindi
C++ : Operator Example with program explanation in hindi , write a program to find even or odd number
learn about C++ : Operator Example with program explanation in hindi :-
इससे पहले के article मे operators को discuss किया गया है | अब इस article मे इन operators पर based उदाहरनो को discuss करेगे | जिनसे आपके इन सभी operators के concept को अच्छी तरह से समज सकते है |
Example 1
write a program to find even or odd number .
Explanation
1.सबसे पहले एक array को declare किया जाता है | जिसकी size 5 है अतः इसमें 5 values assign की जाती है |
2. looping चलाया जाता है |
3.loop की body मे , array के element पर even और odd की condition को check किया जाता है |
जब i=0 होती है तब array की first element पर even और odd की condition को check किया जाता है |
जब i=1 होती है तब array की second element पर even और odd की condition को check किया जाता है |
जब i=2 होती है तब array की third element पर even और odd की condition को check किया जाता है |
जब i=3 होती है तब array की fourth element पर even और odd की condition को check किया जाता है |
जब i=4 होती है तब array की fifth element पर even और odd की condition को check किया जाता है |
अगर element even होता है तब a[i] is even . display होता है अन्यथा a[i] is odd .display होता है |
4. प्रोग्राम को क्लोज कर देते है |
source code
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Date :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
if(a[i]%2 ==0)
{
cout<<a[i]<<“is even.”<<endl;
}
else
{
cout<<a[i]<<“is odd.”<<endl;
}
getch();
}
इसका आउटपुट होगा :-
Enter Array Date : 12 23 11 24 32
12 is even.
23 is odd.
11 is odd.
24 is even.
32 is even.
Example 2
write a program to find even or odd number using Bitwise operator .
Explanation
1.सबसे पहले एक array को declare किया जाता है | जिसकी size 5 है अतः इसमें 5 values assign की जाती है |
2. looping चलाया जाता है |
3.loop की body मे , array के element पर even और odd की condition को check किया जाता है | even or odd condition को bitwise and operator के लिए use किया जाता है |
किसी value की बिट पैटर्न का most right बिट से value के even और odd को check करने के use किये जाता है | अगर right most बिट ‘1’ होती तब value even होती है अन्यथा odd होती है |
जब i=0 होती है तब array की first element पर even और odd की condition को check किया जाता है |
जब i=1 होती है तब array की second element पर even और odd की condition को check किया जाता है |
जब i=2 होती है तब array की third element पर even और odd की condition को check किया जाता है |
जब i=3 होती है तब array की fourth element पर even और odd की condition को check किया जाता है |
जब i=4 होती है तब array की fifth element पर even और odd की condition को check किया जाता है |
अगर element even होता है तब a[i] is even . display होता है अन्यथा a[i] is odd .display होता है |
4. प्रोग्राम को क्लोज कर देते है |
source code
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5];
cout<<“Enter Array Date :”<<endl;
for(i=0;i<5;i++)
{
cin>>a[i];
}
for(i=0;i<5;i++)
{
if(a[i]& 1)
{
cout<<a[i]<<“is even.”<<endl;
}
else
{
cout<<a[i]<<“is odd.”<<endl;
}
getch();
}
इसका आउटपुट होगा :-
Enter Array Date : 12 23 11 24 32
12 is even.
23 is odd.
11 is odd.
24 is even.
32 is even.
Example 3
write a program to find averge of 10 values .
Explanation
1.सबसे पहले एक array को declare किया जाता है | जिसकी size 10 है अतः इसमें 10 values assign की जाती है |
2. looping चलाया जाता है |
3.loop की body मे , array के element को add किया जाता है | जिसे sum variable मे assign किया जाता है |
जब i=0 होती है तब array की first element को sum =0 से add किया जाता है |
जब i=1 होती है तब array की second element , sum से add किया जाता है |
जब i=2 होती है तब array की third element, sum (जिसमे first और second element का addition होता है ) को add किया जाता है |
जब i=3 होती है तब array की fourth element sum (जिसमे first,second और third element का addition होता है ) को add किया जाता है |
इस तरह से array के सभी 10 values को add करके sum variable मे assign कर दिया जाता है |
4.फिर average = sum / Number of values ; से average को calculate कर लिया जाता है |
5. average की value को display कर दिया जाता है |
source code
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10];
cout<<“Enter Array Date :”<<endl;
for(i=0;i<10;i++)
{
cin>>a[i];
}
for(i=0;i<10;i++)
{
sum+=a[i];
}
int avg= sum/10;
cout<<“Average :”<<avg<<endl;
getch();
}
इसका आउटपुट होगा :-
Enter Array Date : 11 24 32 11 22 32 43 67 78 98
Average : 41.8
Example 4
write a program to print table of number .
Explanation
1.सबसे पहले यूजर द्वारा number को input करा लेते है जिसके tabel को print करना है |
2.उसके बाद looping की जाती है |
3.loop के body मे , variable mul = number * i से tabel की value को find कर लिया जाता है |
4. उसके बाद cout statement से number * i = mul को display करदिया जाता है |
5.ये loop 10 बार चलाया जाता है |
source code
#include<iostream.h>
#include<conio.h>
void main()
{
int mul,number ,i;
cout<<“Enter number : “<<endl;
cin>>number;
cout<< “Table of “<<number<<endl;
for(i=1;i<=10;i++)
{
mul=number i;
cout<<number <<“*”<< i <<“=”<< mul<<endl;
}
getch();
}
इसका आउटपुट होगा :-
Enter number : 4
Table of 4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
4*9=36
4*10=40
Example 5
write a program to find third angel of a triangle .
Explanation
1.सबसे पहले यूजर द्वारा दो angle के value को input करा लेते है जिसे angle1 और angle2 मे assign करा देते है |
2.उसके बाद angle3 = 180 – (angle1+angle2) से तिरसा angle को calculate कर लिया जाता है |
3.इस तीरसे angle को display कर दिया जाता है |
source code
#include<iostream.h>
#include<conio.h>
void main()
{
int angle1 ,angle2 ,angle3 ;
cout<<“Enter angle1 : “<<endl;
cin>>angle1 ;
cout<<“Enter angle2 : “<<endl;
cin>>angle2 ;
angle3 = 180- (angle1 + angle2);
cout<<“Third Angel : “<<angle3;
getch();
}
इसका आउटपुट होगा :-
Enter angle1 : 70
Enter angle2 : 50
Third Angel : 60
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
4 weeks ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
4 weeks ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
4 weeks ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
4 weeks ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
1 month ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
1 month ago