Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is an intro to computer programming question in C language. Please make it

ID: 3711756 • Letter: T

Question

This is an intro to computer programming question in C language. Please make it as simple as possible!

Given the array of strings beatles[] whose contents include “john”, “paul”, “george” and “ringo”, build a search function called search() that will search the list for names to see whether they were one of the Beatles or not. Start with

char * beatles[4] = {“john”, “paul”, “george”, “ringo”};

Now write a search function to search this array and see whether “george” and “ringo” are in that list. Then check to see whether “mick” and “bruce” are on that list.

Explanation / Answer

#include<stdio.h>
int search(char *beetles[],int size ,char* key)
{
    for(int i=0;i<size;i++)
    {
        if(strcmp(beetles[i],key)==0)
            return 1;
    }
    return 0;

}

int main()
{
char *beetles[] = {"john","paul","george","ringo"};
int result = search(beetles,4,"john");
int result2 = search(beetles,4,"mick");
int result3 = search(beetles,4,"bruce");
printf("%d %d %d",result,result2,result3);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote