Write a code to create an array with the following elements a,b,c,d,e,f,g,h,i,j,k. Test if the array contain a specific character provided by the user. If found display the index number else display "item not found."
#include <iostream>
using namespace std;
int main()
{
char a[11];
for (int i = 0; i < 11; i++)
a[i] = 'a' + i;
char s;
cin >> s;
int flag = -1;
for (int i = 0; i < 11; i++)
if (a[i] == s)
flag = i;
if (flag == -1)
cout << "item not found";
else
cout << flag;
}
Comments
Leave a comment