Function getThreeOrFourDigitsThe function/method getThreeOrFourDigits accepts two arguments – SIZE and arr. SIZE represents the size of the integer array arr.
The function/method getThreeOrFourDigits must return an array of integers containing the three-digit or four-digit integers in the given array arr. If there is no such integer in the given array arr, then the function must return an array of size 1 with the value -1.
Your task is to implement the function getThreeOrFourDigits so that it passes all the test cases.
The following structure is used to represent the boundedArray and is already defined in the default code (Do not write this definition again in your code).
typedef struct BoundedArray
{
int SIZE;
int *arr;
} boundedArray;
IMPORTANT: Do not write the main() function as it is already defined.
Example Input/Output 1:
Input:
6
34 124 4 3400 2020 505
Output:
Old Array: 34 124 4 3400 2020 505
New Array: 124 3400 2020 505
Explanation:
Here N = 6.
The three-digit or four-digit integers in the given array are 124, 3400, 2020 and 505.
So the returned array contains the following 4 integers
124 3400 2020 505
Example Input/Output 2:
Input:
5
12 57 1 58 19087
Output:
Old Array: 12 57 1 58 19087
New Array: -1
#include <stdio.h>
#include <stdlib.h>
typedef struct BoundedArray
{
int SIZE;
int arr;
}
boundedArray; boundedArray getThreeOrFourDigits(int SIZE, int arr[])
{
boundedArray b;
boundedArray *ptr;
ptr=&b;
int i,temp[1001],k=0;
for(i=0;i<SIZE;++i)
{
if(arr[i]>=100 && arr[i]<=9999)
{
temp[k]=arr[i];
k++;
}
}
if (k==0)
{
temp[k]=-1;
k++;
}
b.SIZE=k;
b.arr=temp;
return ptr;
}
int main()
{
int N;
scanf("%d", &N);
int arr[N];
for(int index = 0; index < N; index++)
{
scanf("%d", &arr[index]);
}
boundedArray *bArr = getThreeOrFourDigits(N, arr);
printf("Old Array: ");
for(int index = 0; index < N; index++)
{
printf("%d ", arr[index]);
}
printf("nNew Array: ");
for(int index = 0; index < bArr->SIZE; index++)
{
printf("%d ", bArr->arr[index]);
}
return 0;
}