//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 where 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.//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int checkArray(float* ary, int numfloats);
int main()
{
float* ary;
int numfloats;
int position;
float ary[numfloats];
printf("Enter the number of floats in the array: ");
scanf_s("%d",&numfloats);
printf("Begin entering your values (floating points)\n");
for(int i = 0; i < numfloats; i++)
{
printf("Enter number %2d: ", i + 1);
scanf_s("%d", &ary[i]);
}//for
float ary = (numfloats, ary);
if (position >= 0)
printf("The first occurance of the number is in position: %d\n", position);
else
printf("Error.This number does not appear in the array\n");
getchar();
return 0;
}
int checkArray(float* ary, int numfloats)
{
float searchNum;
float precision;
int position = -1;
int num;
printf("\nWhat number are you searching for? ");
scanf_s("%f", &searchNum);
printf("\nEnter the precision you would like. ");
printf("\nEnter 0 for exact values. ");
scanf_s("%f", precision);
for(num=0; num < numfloats; num++)
{
Edited by WingedPanther, 20 March 2010 - 07:44 PM.
add code tags


Sign In
Create Account

Back to top









