C language: Implementing a function that verifies that a given array contains a given number

Asked 2 years ago, Updated 2 years ago, 52 views

#define _crt_secure_no_warnings
#define size 5
#include<stdio.h>
void GetIntArray(int* v, int n);
int Isinclude(int* v, int n, int val);

int main()
{
    int v[size];
    int n = 5;
    int val;

    printf("Enter val:");
    scanf("%d", &val);

    GetIntArray(&v, n);
    Isinclude(&v, n, val);
}
void GetIntArray(int* v, int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        scanf("%d", &v[i]);
    }
}

int Isinclude(int *v, int n, int val)
{
    int i;

    for (i = 0; i < n; i++)
    {
        if (v[i]==val)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
}

You must check if the array int v[ ] delivered as an array pointer-type parameter contains an integer val, and if it does, create a function that returns 1 or 0 int IsInclude (int *v, int, int val).

(1,2,3,4,5) and (2,3,4,5,6) If two inputs are entered, The output should come out like 2, 3, 4, 5, but I don't know how to squeeze it.

I'd appreciate your help.

pointer array

2022-09-20 17:02

1 Answers

I don't know if I understand the problem. I think you can fill it out in the order below.

And you need to modify the part where the isInclude function compares only the first factor and returns it.


2022-09-20 17:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.