JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

Write a program to find a prime number , an armstrong number , to compare two strings

इससे पहले के article मे कई उदाहरनो को discuss किया जाता है अब इस article मे , हम कई उदाहरनो को discuss करेगे जिससे आपके c++ के concept को discuss करगे | सबसे पहले डट type और variable देक्लार्तिओं और looping के उदाहरनो को discuss करेगे |उदाहरन -1
Write a program to find a prime number.
इस उदाहरनो मे ,  prime number को find किया जाता है |
explantion
सबसे पहले यूजर द्वारा value को input किया जाता है जिसको variable ‘a’ को assign किया जाता है |
उसके बाद condition को check किया जाता है | condition मे , अगर value किसी number से divide होता जो की ‘2’ से start होते है तब ये value prime number होती है |
अन्यथा ये number prime number नहीं होती है |
इसके बाद प्रोग्राम को end कर देते है |
source code
#include<iostream.h>
#include<conio.h>
int prime (int);
void main()
{
int a,c;
cout<<“Enter a :”<<endl;
cin>>a;
c= prime(a);
if(c==1)
{
cout<<a<<“is Prime number.”;
}
else
{
cout<<a<<“is not Prime number.”;
}
}
getch();
}
int compare (int e)
{
int i ;
if(e<=1)
{
return 0;
}
int count ;
for(i=2;i<=e/2;i++)
{
if((e%i)==0)
{
return 1;
break;
}
}
}

उदाहरन -2
Write a program to find an armstrong number.
इस उदाहरनो मे ,  armstrong number को find किया जाता है |
explantion
armstrong number ये number होते है जीके लिए निन्म condition फॉलो होते है :-
अगर number = 123 होती है  तब  123 = (1*1*1)+(2*2*2)+(3*3*3)
जब इस condition true होती है तब value armstrong number होगी अन्यथा value armstrong number नहीं है |
सबसे पहले यूजर द्वारा value को input किया जाता है जिसको variable ‘a’ को assign किया जाता है |
उसके बाद value से last डिजिट को find किया जाता है जिसके cube को sum मे add किया जाता है | और फिर second digit के cube को sum मे add किउया जाट है |
उसके बाद पहली डिजिट के cube को sum मे add किये जाता है |
अगर sum = value हो ती है तब value को armstrong number होगी |
अन्यथा value armstrong number नहीं होगी |
source code
#include<iostream.h>
#include<conio.h>
int armstrong (int);
void main()
{
int a,c;
cout<<“Enter a :”<<endl;
cin>>a;
c=  armstrong (a);
if(c==a)
{
cout<<a<<“is armstrong number .”;
}
else
{
cout<<a<<“is not armstrong number .”;
}
}
getch();
}
int armstrong (int e)
{
int sum =0;
int i=e ;
while(i>0)
{
r=i%10;
sum = sum + (i*i*i);
i=i/10;
}
return (sum);
}

उदाहरन -3
Write a program to compare two strings .
इस उदाहरनो मे ,  दो string को compare किया जाता है |
explantion
सबसे पहले दो string variable को declare किया जाता है |
उसके बाद यूजर द्वारा string value को input किया जाता है | इसे string variables मे assign कर दिया जाता है |
looping की जाती है |
जब i=0 होती है तब दोनों string के first elements को compare किया जाता है |
जब i=1 होती है तब दोनों string के second elements को compare किया जाता है |
जब i=2 होती है तब दोनों string के third elements को compare किया जाता है |
जब i=3 होती है तब दोनों string के fourth elements को compare किया जाता है |
जब i=4 होती है तब दोनों string के  fifth elements को compare किया जाता है |
जब i=5 होती है तब दोनों string के  sixth  elements को compare किया जाता है |
ये loop तब तक चलता है जब तक string मे  ‘\0’ pointer नहीं आ जाता है |
अगर string मे character मे match नहीं होता है तब Both string are not same. अन्यथा  Both string are same. massage display होगा |
source code
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
string a,b;
cout<<“Enter string :”<<endl;
cin>>a;
cout<<“Enter string :”<<endl;
cin>>b;
for(i=0;a[i]!=”\0″ && b[i]!=”\0” ; i++ )
{
if(a[i]==b[i])
{
count =0;
}
else
{
count =1 ;
}
}
if(count==0)
{
cout<<“Both string are same.”;
}
else
{
cout<<“Both string are not same.”;
}
getch();
}

उदाहरन -4
Write a program to add two strings .
इस उदाहरनो मे ,  दो string को add किया जाता है |
explantion
सबसे पहले दो string variable को declare किया जाता है |
उसके बाद यूजर द्वारा string value को input किया जाता है | इसे string variables मे assign कर दिया जाता है |
उसके बाद string class मे उपस्थित strcat() function से string को जोड़ा जाता है | इसके लिए merge string को एक नए string मे assign किया जाता है |
इसके बाद इस string variable को display किया जाता है |
source code
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
string a,b,c;
cout<<“Enter string :”<<endl;
cin>>a;
cout<<“Enter string :”<<endl;
cin>>b;
c=strcat(a,b);
cout<<“Merge string : “<<c<<endl;
getch();
}

उदाहरन -5
Write a program to display a fibbocaci series .
इस उदाहरनो मे ,  fibbocaci seriesफी को display किया जाता है |
explantion
fibbocaci series निन्म होती है
0 1 1 2 3 5 8 13 21
इसके लिया यूजर द्वारा fibbocaci series के range को input किया जाता है जिसके use fibbocaci series की limit को display किया जाता है |
इसके बाद loop चलाया जाता है | इसमें
अगर i की  value ‘1’ के सामान और छोटी होती है तब fibbocaci series series के  element , i की value को display किया जाता है |
अन्यथा c= first + second display होता है |
source code
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int  a=0,b=1,c;
int range ;
cout<<“enter range :”;
cin>>range;
for(i=0;i<range;i++)
{
if(i<=1)
{
b=i;
}
else
{
c=a+b;
a=b;
b=c;
}
cout<<c;
};

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

1 month ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

1 month ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

1 month ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

1 month ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

2 months ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

2 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now