हिंदी माध्यम नोट्स
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
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
16 hours ago
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
16 hours ago
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
2 days ago
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
2 days ago
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
3 months ago
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…
3 months ago