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

Write a function that verifies if a given number exists in an array of floats. T

ID: 3825032 • Letter: W

Question

Write a function that verifies if a given number exists in an array of floats. The function is supposed to return the first position in which the number is encountered. If the given number does not exist, the function returns -1. Then write a program that asks the user to enter an array of floats and calls the function. The prototype of the function should be like: int find (floats a[], float number); Consider the following array of floats If the number to be searched is 5.4 the function returns -1 If the number to be searched is 9 the function returns 2

Explanation / Answer

#include <stdio.h>
int n;
int find(float a[], float number)
{
int i;
for(i = 0; i < n; i++)
{
if (a[i] == number)
{
return i;
}
}
return -1;
}

int main()
{
printf("Enter number of entry in array of float: ");
scanf("%d", &n);
  
int i;
float a[n];
  
for(i = 0; i < n; i++)
{
printf("Enter element %d of array: ", i);
scanf("%f", &a[i]);
}
  
printf("Seacrhed 5.4 the function returns %d ", find(a, 5.4));
printf("Seacrhed 9 the function returns %d ", find(a, 9));

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote