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

You have 3 parallel arrays, 2 of which will be to read in, with up to 25 element

ID: 3835959 • Letter: Y

Question

You have 3 parallel arrays, 2 of which will be to read in, with up to 25 elements each. The first is an integer, the second is a double, and the third is a character. Each read will read in a pair of values, see below. The last read will have a 0 0 with some whitespace between. NO global variables can be used. Write a function to read this input data and call it READ_DATA. The READ_DATA function only does the read of data and returns the number of elements read in function name. Call your program "username EXAM3.c". Write another function (not a one liner) called SEARCH_DATA with the following parameters (there will be NO printed output in this function): the 3 arrays number of elements in the arrays number of search to find error, not found in array (in function name) Write a main program that inputs the following into the first 2 arrays: 12 123.45 2 234.1 98 98.1234 67 12345.0 45 6765.123 66 1.12345 0 0 (not included in input routines) Next read in an integer, one at a time, and call your function above (SEARCH_DATA) to find it or not find it, zero ends the input, t search function will be updating the third parallel array from an 'N' to a Y, if found: 98 44 66 2 0 (not included in input routines) print your output in your main function, as follows: Your output will be: Yourname CSCI1110 Input Number: Number Found? 99 9999999.9999999 YES Remember to include comments, proper indentation, variable names, etc. as discussed in class. SAMPLE OUTPUT: 2 234.1000 YES 66 NO

Explanation / Answer

PROGRAM CODE:

#include <stdio.h>

int READ_DATA(int intNumber[], double doubleNumber[])
{
   int counter = 0;
   while(1)
   {
       printf(" Enter numbers: ");
       int intNum;
       double doubleNum;
       scanf("%d %lf", &intNum, &doubleNum);
       //printf("%d,%f", intNum, doubleNum);
       if(intNum == 0 && fabs (doubleNum) < 0.0001)
           break;
       else
       {
           intNumber[counter] = intNum;
           doubleNumber[counter++] = doubleNum;
       }
   }
   return counter;
}

void SEARCH_DATA(char found[], int inputNumber[], double number[], int num, int toFind)
{
   for(int i=0; i<num; i++)
   {
       if(inputNumber[i] == toFind)
       {
           long subNumber = number[i]*100000;
           int divider = 10;
           if(inputNumber[i]>9)
               divider = 100;
           while(1)
           {
              
               if(subNumber%divider == inputNumber[i])
               {
                   found[i] = 'Y';
                   return;
               }
               else
               {
                   subNumber = subNumber/10;
               }
               if(subNumber==0)
                   return;
               //printf("%d ", subNumber);
           }
       }
   }
}

int main(void) {
   int inputNumber[25];
   double number[25];
   char found[25];
   int numberOfElements = READ_DATA(inputNumber, number);
   for(int i=0; i<numberOfElements; i++)
       found[i] = 'N';
   while(1)
   {
       printf(" Enter a number to search: ");
       int num;
       scanf("%d", &num);
       if(num==0)
           break;
       else
       {
           SEARCH_DATA(found, inputNumber, number,numberOfElements, num);
       }
   }
   printf(" Input Number Number Found? ");
   printf("------------ -------------- ------ ");
   for(int i=0; i<numberOfElements; i++)
   {
       printf(" %d %f %c ", inputNumber[i], number[i], found[i]);
   }
   return 0;
}

OUTPUT:

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