C PROGRAM TO PRINT THE VALUES IN AN ARRAY THAT LIE BETWEEN THE TWO INTEGERS
Consider the following I/O samples.
SAMPLE INPUT: 5
10 3 5 6 8
3 //first number
8 // second number
SAMPLE OUTPUT: 5 6 // 5 and 6 lies between 3 and 8
The algorithm used here is :
- Input the number of elements.
- Input the array elements.
- Input the first and second number.
- Check for the values using for loop and if condition
- Print the output.
C PROGRAM:
#include<stdio.h>
int main()
{
int n,arr[100],i,first,sec;
printf("Enter the number of elements:");
scanf("%d",&n);
printf("Enter the array elements:");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("Enter the first number");
scanf("%d",&first);
printf("Enter the second number:");
scanf("%d",&sec);
printf("The numbers are:\n");
for(i=0;i<n;i++) // check for the values
{
if(arr[i]>first && arr[i]<sec)
printf("%d\t",arr[i]);
}
return 0;
}
OUTPUT:
The given source code in C program "to find the values that lie between the two integers in an array" is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment