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

Lunix #include Write a C program that ask users to input a series of integers wh

ID: 3818596 • Letter: L

Question

Lunix #include

Write a C program that ask users to input a series of integers which are in increasing order (i.e., an integer is NOT smaller than the one immediately before it). The input will end with the number 0. Assume users will never input more than 10 integers before input 0. After users input all the numbers, ask the user input another number m. Finally print to screen if the number m is in the series

(example

Input a series of integers (ended with 0): 1 3 4 5 7 8 15 17 20 0

Input a number to find from the series: 9

The number 9 is not in the series you gave.)

You have to use an array to store the input numbers a[0], ..., a[n-1]

find if m is in array a from index 0 to n-1found = search(a, 0 , n-1, m)

if found print m is found in a. Otherwise print m is not found in a

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

//boolean function search
bool search(int a[], int l , int h, int m)
{
int i;
for(i=0;i<h;i++)
{
if(a[i]==m)
return true;

}
return false;

}

//main function
int main()
{
//integer array with max element 10
int a[10];
int i;
int m;
bool found;

printf("Enter a series of integers which are in increasing order ");

//for loop to read a series of integers
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);

if(a[i]==0)
{
break;

}

}

// read m
printf(" Input a number to find from the series:");
scanf("%d", &m);

//calling search function here n=10
found=search(a, 0 , 10, m);


if(found)
{
//if found=true
printf(" The number %d found in the series you gave.",m);

}
else
{

//if found=false
printf(" The number %d is not in the series you gave. ",m);

}


return 0;
}

---------------------

output sample 1:

Enter a series of integers which are in increasing order
1
2
3
4
5
6
7
0

Input a number to find from the series:5

The number 5 found in the series you gave.

------------------------

output sample 2:-

Enter a series of integers which are in increasing order
1
3
4
5
7
8
15
17
20
0

Input a number to find from the series:9

The number 9 is not in the series you gave.

--------------------------------

output sample 3:-

Enter a series of integers which are in increasing order
1
2
3
4
5
6
7
8
9
0

Input a number to find from the series:5

The number 5 found in the series you gave.

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.