JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: C Language in hindi

String : Advance Example (Part 1 ) in c language in hindi , स्ट्रिंग के उदाहरण हिंदी में समझे c भाषा

स्ट्रिंग के उदाहरण हिंदी में समझे c भाषा , String : Advance Example (Part 1 ) in c language in hindi :-
string एक character array होती है जो की कई operation मे use होती है |इस article मे , string के कुछ advance प्रोग्राम को पढ़गे जिससे की हम string के concept को अच्छी तरह समज सके |इसका syntax है |char string_name[size];

यहा पर
string_name : ये string का नाम होता है |
size : ये string का नाम होता है |


string का last डिजिट हमेशा null pointer होता है |इसलिए charecter size = size-1 होगी |

उदाहरण -1 :
Write a c program to eliminate blank space into string .
इस उदाहरन मे , string मे से blank space को eliminate किया जाता है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद दुसरे string variable ‘check’ को declare किया जाता है |
3.looping होती है |loop जब तक चलता है तब तक string ‘statement’ मे null pointer नहीं आ जाता है |
3.i- string ‘statement के charecter को blank space से compare किया जाता है |
अगर white space होता है तब charecter को स्किप किया जाता है |
अन्यथा charecter को नयी string check मे copy कर दिया जाता है |
4.नयी string ‘check’ को print कर दिया जाता है |

source code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char statement [50];
char check [50];
int length ;
printf(“Enter Statement “);
scanf(“%s”,statement);
length=strlen(statement);
for (i=0;i<length;i++)
{
if(statement[i]=” “)
{
i++;
}
else
{
check[i]=statement [i];
i++;
}
}
printf(“String Without white space \n”);
printf(“%s”,check);
getch();
}

इस उदहारण मे , strlen() function  का use किया गया है जिससे string की length को calculate किया जाता है |
इसका आउटपुट होगा :
Enter Statement Parth is good boy.
String Without white space
Parthisgoodboy.

उदहारण 2
Write a c program to eliminate string into main  string .
इस उदाहरन मे , string मे से किसी word / char  को eliminate करना  है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद दुसरे string variable ‘remove’ को declare किया जाता है |जिसमे यूजर द्वारा eleminate की जाने वाली string store होती है |
3.function remove को call किया जाता है जिसके parameter मे दोनों string को pass किया जाता है |यहा पर call by reference को used किया जाता है |

remove() मे
1.इस function मे , दोनों string की size को calculate किया जाता है |इस size को l1 और l2 मे store कर देते है |
2. loop चलाया जाता है जिसमे string remove के सभी character को string statement मे check किया जाता है |अगर word मिल जाता है तब next step proceed होती है |
3. जहा पर word मिलता है string को उतने place shift कर दिया जाता है

source code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void  remove(char * ,char *);
void main()
{
char statement [50];
char remove [50];
int length ;
printf(“Enter Statement “);
scanf(“%s”,statement);
printf(“Enter remove string  “);
scanf(“%s”,remove);
printf(“String before remove \n”);
printf(“%s”,statement);
remove ( statement,remove ) ;
printf(“String After remove \n”);
printf(“%s”,statement);
getch();
}
void remove (char * s , char  *r)
{
int i , j ,l1 ,l2;
int count ;
l1 =strlen(s);
l2= strlen(r);
for(i=0;i<l1-l2;i++)
{
count =1;
for(j=0;j<l2;j++)
{
if(s[i+j]!= r[j])
{
count =0;
break;
}
}
if(s[i+j]!=’ ‘ &&s[i+j]!=’/t’ && s[i+j]!=’/n’ )
{
count =0;
}
if (count==1)
{
for(j=i; j<= l1-l2;j++)
{
l1=l2-l1;
i–;
}
}
}
इस उदहारण मे , strlen() function  का use किया गया है जिससे string की length को calculate किया जाता है |
इसका आउटपुट होगा :
Enter Statement Parth is good boy.
Enter remove string Parth 
String before remove 
Parth is good boy.
String After remove
is good boy.

उदाहरण -3 :
Write a c program to count frequency of character  into string .
इस उदाहरन मे , string मे से किसी character की frequency को calculate करने के  किया जाता है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद दुसरे character  variable ‘check’ को declare किया जाता है |जिसमे यूजर द्वारा दिए गये character की value को assign किया जाता है |
3.looping होती है |loop जब तक चलता है तब तक string ‘statement’ मे null pointer नहीं आ जाता है |
3.i- string ‘statement के character को  character  variable ‘check’ से compare किया जाता है |
अगर  character  variable ‘check’ होता है तब count को increase किया जाता है |
अन्यथा  i की value को increase किया जाता  है |
4.नयी string ‘check’ को print कर दिया जाता है |

source code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char statement [50];
char check ;
int length ;
printf(“Enter Statement “);
scanf(“%s”,statement);
printf(“Enter Character that you want to check “);
scanf(“%c”,&check);
length=strlen(statement);
int count =0;
for (i=0;i<length;i++)
{
if(statement[i]== check )
{
count++;
i++;
}
else
{
i++;
}
}
if(count==0)
{
printf(“Sorry ! Character does not come into string”);
}
else
{
printf(” Character come %d times into string”, count );
}
getch();
}

इस उदहारण मे , strlen() function  का use किया गया है जिससे string की length को calculate किया जाता है |
इसका आउटपुट होगा :
Enter Statement Parth is good boy.
Enter Character that you want to check a
Character come 1 times into string
और
Enter Statement Parth is good boy.
Enter Character that you want to check o
Character come 3 times into string

उदाहरण -4 :
Write a c program to count  highest frequency of character  into string .
इस उदाहरन मे , string मे से किसी character की highest frequency को calculate करने के  किया जाता है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद एक array को declare करते है जो सभी character की frequency को hold करता है | इस array के सभी element की initial value ‘0’ होती है |
3.looping होती है |loop जब तक चलता है |सबसे पहले array के index set किया जाता है |array के index character के ascii value होती है |
अगर character की ascii value के हिसाब से array की index मे value इनक्रीस होती है |
अगर character ‘a’ है तब ascii value 77 है तो array के 77 index मे assign ‘0’ मे increment होगा और इसकी value ‘1’ हो जाएगी |
अगर character ‘b’ है तब ascii value 78 है तो array के 78 index मे assign ‘0’ मे increment होगा और इसकी value ‘1’ हो जाएगी
अगर दुबारा |character ‘b’ है तब भी  ascii value 77 है तो array के 77 index मे assign ‘1’ मे increment होगा और इसकी value ‘2’ हो जाएगी|
4.use बाद array मे maximum का लॉजिक लगा कर highest frequency को calculate कर लिया जाता है |

source code :
#include<stdio.h>
#include<conio.h>
#define ARRAY_SIZE  255
void main()
{
char statement [50];
char max[ARRAY_SIZE];
int length ;
int index;
printf(“Enter Statement “);
scanf(“%s”,statement);
length=strlen(statement);
for (i=0;i<ARRAY_SIZE;i++)
{
max[i]=0;
}
for(i=0;i<length;i++)
{
index=int(statement[i]);
max[index]=max[index]+1;
}
int m=0;
for(i=0;i<=ARRAY_SIZE;i++)
{
if(max[i]>max[m])
{
m=i;
}
printf(“maximum Frequency = %d  for %c”, max[m] ,m );
getch();
}

इस उदहारण मे , strlen() function  का use किया गया है जिससे string की length को calculate किया जाता है |
इसका आउटपुट होगा :
Enter Statement parth is good boy.
maximum Frequency = 3  for o

उदाहरण -5 :
Write a c program to print frequency of each character  into string .
इस उदाहरन मे , string मे से सभी  character की  frequency को print  करना  है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद एक array को declare करते है जो सभी character की frequency को hold करता है | इस array के सभी element की initial value ‘0’ होती है |
3.looping होती है |loop जब तक चलता है |सबसे पहले array के index set किया जाता है |array के index character के ascii value होती है |
अगर character की ascii value के हिसाब से array की index मे value इनक्रीस होती है |
अगर character ‘a’ है तब ascii value 77 है तो array के 77 index मे assign ‘0’ मे increment होगा और इसकी value ‘1’ हो जाएगी |
अगर character ‘b’ है तब ascii value 78 है तो array के 78 index मे assign ‘0’ मे increment होगा और इसकी value ‘1’ हो जाएगी
अगर दुबारा |character ‘b’ है तब भी  ascii value 77 है तो array के 77 index मे assign ‘1’ मे increment होगा और इसकी value ‘2’ हो जाएगी|
4.उसके बाद array के element को print कर देना है |

source code :
#include<stdio.h>
#include<conio.h>
#define ARRAY_SIZE  255
void main()
{
char statement [50];
char max[ARRAY_SIZE];
int length ;
int index;
printf(“Enter Statement “);
scanf(“%s”,statement);
length=strlen(statement);
for (i=0;i<ARRAY_SIZE;i++)
{
max[i]=0;
}
for(i=0;i<length;i++)
{
index=int(statement[i]);
max[index]=max[index]+1;
}
for(i=0;i<ARRAY_SIZE;i++)
{
if(max[i]==0)
{
i++;
}
else
{
printf (“frequency of %c = %d “, i ,max[i]);
}
}
getch();
}

इस उदहारण मे , strlen() function  का use किया गया है जिससे string की length को calculate किया जाता है |
इसका आउटपुट होगा :
Enter Statement parth is good boy.
frequency of p = 1
frequency of a = 1
frequency of r = 1
frequency of t = 1
frequency of h = 1
frequency of i = 1
frequency of s = 1
frequency of g = 1
frequency of o = 3
frequency of d = 1
frequency of b = 1
frequency of y = 1

उदाहरण -6 :
Write a c program to check palindrome string .
इस उदाहरन मे , string  palindrome होने की condition को check किया जाता है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
2.उसके बाद दुसरे string variable ‘check’ को declare किया जाता है |जिसमे string का reverse assign होता है |
3.looping होती है |loop जब तक चलता है तब तक string ‘statement’ मे first element  नहीं आ जाता है |
3.i- string statement के last charecter को string ‘reverse’ के first element मे assign करते है |हर बार i और j की value मे increament हो जाता है |
4. उसके बाद string और reverse string को check किया जाता है | अगर दोनों same होते है तब string is palindrome. का message आ जाता है |
अन्यथा string is not palindrome. message आ जाता है |

source code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char statement [50];
char reverse [50];
int length ;
printf(“Enter Statement “);
scanf(“%s”,statement);
length=strlen(statement);
int j=0;
for (i=length-1;i>=0;i–)
{
reverse[j]=statement[i];
j++;
}
}
int flag=0;
for (i=0;i<0;i++)
{
if(reverse[i]==statement[i]);
{
flag =0;
}
else
{
flag=1;
break;
}
if(flag==0)
{
printf(“string is palindrome.”);
}
else{
printf(“string is not palindrome.”);
}
getch();
}

आउटपुट होगा :
Enter Statement madam
string is palindrome.

उदाहरन 7-
Write a c program to convert lowercase to upper case  .
इस उदाहरन मे , string को lowercase तो uppercase मे convert किया जाता है |

Explanation
1.सबसे पहले यूजर से string को input करा लेते है|जिसे  string variable name ‘statement’ मे store कर लेते है
3.looping होती है |loop जब तक चलता है तब तक string ‘statement’ मे null pointer नहीं आ जाता है |
3.i- string statement के character की value को “A” और “Z” के बीच की value को check किया जाता है |अगर बीच नहीं है तब character की ascii value मे 32 को add कर दिया जाता है |
4. उसके बाद string को print कर दिया जाता है |

source code :
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char statement [50];
int length;
printf(“Enter Statement “);
scanf(“%s”,statement);
length=strlen(statement);
int check;
for (i=length-1;i>=0;i–)
{
check=int(statement[i]);
if(check >= 65 && check <= 90)
{
statement[i]=statment[i]+32;
}
}
printf(“%s”,statement);
getch();
}

आउटपुट होगा :
Enter Statement madam
MADAM

Sbistudy

Recent Posts

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

2 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

4 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

6 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

6 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

6 days 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