हिंदी माध्यम नोट्स
Write a program to find a prime number , an armstrong number , to compare two strings
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;
};
Recent Posts
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
बैराठ सभ्यता कहाँ स्थित है वर्तमान में bairath civilization in rajasthan in hindi present location
bairath civilization in rajasthan in hindi present location बैराठ सभ्यता कहाँ स्थित है वर्तमान में…
आहड़ सभ्यता की प्रमुख विशेषता , स्थल उत्खनन किसने किया कहाँ स्थित है ahar civilization in hindi
ahar civilization in hindi आहड़ सभ्यता की प्रमुख विशेषता , स्थल उत्खनन किसने किया कहाँ…
कालीबंगा सभ्यता के नोट्स , खोज कब और किसने की के बारे में kalibanga sabhyata in hindi
kalibanga sabhyata in hindi कालीबंगा सभ्यता के नोट्स , खोज कब और किसने की के…
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…