कार्य निर्दिष्ट वर्ण घटना के बाद दिए गए समय के लिए प्रिंट करना है जो उपयोगकर्ता द्वारा निर्दिष्ट किया गया है
Input : string = {“I am harsh vaid “}
Char =’a’
Count =2
Output : rsh vaid इसका मतलब है कि उपयोगकर्ता निर्दिष्ट वर्ण 'ए' और इसकी घटना 2 इसलिए आउटपुट स्ट्रिंग को दो घटनाओं के बाद प्रदर्शित किया जाना चाहिए।
एल्गोरिदम
START Step 1 -> input character in ch(e.g. ‘a’) and count(e.g. 2) as int Step 2 -> declare and initialize n with size of a string by sizeof(string)/sizeof(string[0]) Step 3 - > Loop For i to 0 and i<n and i++ IF count > 0 IF string[i]==ch Count=count-1 End IF Continue End IF Else Print string[i] End Else Step 4 -> End For STOP
उदाहरण
#include <stdio.h>
int main(int argc, char const *argv[]) {
char string[] = {"I am Harsh Vaid"};
char ch = 'a';
int i, count = 2;
int n = sizeof(string)/sizeof(string[0]);
for( i = 0; i < n; i++ ) {
if(count>0) {
if(string[i]==ch) {
count--;
}
continue;
}
else
printf("%c", string[i]);
}
return 0;
} आउटपुट
यदि हम उपरोक्त प्रोग्राम चलाते हैं तो यह निम्न आउटपुट उत्पन्न करेगा
rsh Vaid