In: Computer Science
In C programming, Thanks
Write a program to determine which numbers in an array are inside a particular range. The limits of the range are inclusive.
You have to write a complete "C" Program that compiles and runs in Codeblocks. (main.c)
1. Declare an array that can contain 5 integer numbers. Use as the name of the array your LastName.
2. Use a for loop to ask the user for numbers and fill up the array using those numbers.
3. Ask the user for the lower limit of the range.
4. Ask the user for the upper limit of the range.
5. Use a for loop to check all the numbers in the array and print the numbers inside the range.
The following is an example of how your program should look when you execute it:
Enter a number to store in the array: 10
Enter a number to store in the array: 90
Enter a number to store in the array: 145
Enter a number to store in the array: 94
Enter a number to store in the array: 97
Enter the lower limit of the range: 90
Enter the upper limit of the range: 99
The numbers in the range are: 90, 94, 97
main.c:
-------
#include <stdio.h>
int main()
{
int karri[5];
int lower, upper;
for(int i=0;i<5;i++)
{
printf("Enter a number to store in the array:");
scanf("%d",&karri[i]);
}
printf("\nEnter the lower limit of the range:");
scanf("%d",&lower);
printf("Enter the upper limit of the range:");
scanf("%d",&upper);
printf("The numbers in the range are:");
for(int i=0;i<5;i++)
{
if(karri[i]>=lower && karri[i]<=upper)
printf(" %d,",karri[i]);
}
printf("\b ");
return 0;
}
Output:
-------
Enter a number to store in the array:10
Enter a number to store in the array:90
Enter a number to store in the array:145
Enter a number to store in the array:94
Enter a number to store in the array:97
Enter the lower limit of the range:90
Enter the upper limit of the range:99
The numbers in the range are: 90, 94, 97