Books

QUESTION

Books price list of [195,200,175,255,105] is sorted. Shop manager wants to check whether book of Rs 195 is available.

ANSWER

#include <stdio.h>
#define MAXSIZE 10
int main()
{
    int array[MAXSIZE];
    int i, j, num, temp;
    scanf("%d", &num);
    for (i = 0; i < num; i++)
    {
        scanf("%d", &array[i]);
    }
    for (i = 0; i < num; i++)
    {
        for (j = 0; j < (num - i - 1); j++)
        {
            if (array[j] > array[j + 1])
            {
                temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
    int toSearch;  
  scanf("%d", &toSearch);

    int found = 0; 
    for(i=0; i<num; i++)
    {
     
        if(array[i] == toSearch)
        {
            found = 1;
            break;
        }
    }

    if(found == 1)
    {
        printf("Book Available");
    }
    else
    {
        printf("Book is not available");
    }
	return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro