code in c++
Prateek is a newbie in C++ programming. He wants to write a program in C++, where he needs to read a string and check whether the string is present.
1 #include
2 #include
3 int main()
4 {
5 char ptr[100];
6 char ch;
7 //Your code goes here
8 std::cout << ch << " is present in " << ptr <<"\n";
9 //Your code goes here
10 std::cout << ch << " is not present in " << ptr << "\n";
11 }
Answers
Answered by
9
Answer:
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char ptr[100];
char ch;
cin.getline(ptr,100);
cin>>ch;
if(memchr(ptr,ch,10))
std::cout << ch << " is present in " << ptr <<"\n";
else
std::cout << ch << " is not present in " << ptr << "\n";
}
Explanation:
Answered by
7
Answer:
#include <cstring>
#include <iostream>
int main()
{
char ptr[100];
char ch;
std::cin.getline(ptr,100);
std::cin>>ch;
if(memchr(ptr,ch,7))
{
std::cout << ch << " is present in " << ptr <<"\n";
}
else
{
std::cout << ch << " is not present in " << ptr << "\n";
}
}
Explanation:
Similar questions