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

in C 1 and 2 please. 3% 6:09 PM Tasks: 1. Write a program which populates an arr

ID: 3593947 • Letter: I

Question

in C
1 and 2 please.



3% 6:09 PM Tasks: 1. Write a program which populates an array with integer values read from a file. We do not know how many intaners are in the file, so you must loop until the end of the file is reached. For this problem, you may not use the function feof ( ). Instead, use the result returned from fscanf () to determine the end-of-file. Recalil, we can set the result of fscan£) to an integer variable, and check to see if the integer variable is equal to the EOF marker. The program must take the items in the array and reverse them. You may use one array only to solve this problem 2. Write a program that populates an array with 20 random integers between 1 - 100. The program must traverse through the array and determine how many times each integer was generated. Use a second array of size 101 to keep track of the number of times each integer was generated. Initialize each item in the second array to 0. For each item in the first array, use it as the index into the second array and increment the contents found in the second array at the corresponding index. Note: for this problem we are willing to trade memory efficiency (the second array is mostly unused) for time efficiency. We know indexing into an array is very efficient. 3. Complete the following programming project 9 on p.

Explanation / Answer

Question No 1

//input.txt should be in same folder.

#include <stdio.h>
#include <stdlib.h>
int main ()
{
   int num;
   FILE * fp;
   fp = fopen ("input.txt", "r+");
   int i=0;
   if (fp == NULL)
   {
       printf("Error Reading File ");
   }
   while(fscanf(fp,"%d",&num) == 1)
   {
       i++;
   }
   fclose(fp);
   fp = fopen ("input.txt", "r+");
   int j=0;
   int arr[i];
   printf(" Reading the values from the file and storing it in an array.... ");
   while(fscanf(fp,"%d",&num) == 1)
   {
        arr[j] = num;
           j++;
   }
   printf(" Values stored in array .... ");
   j=0;
   while(j<i)
    printf("%d ", arr[j++]);
   printf(" Values in reverse order.... ");
   i--;
   while(i>=0)
    printf("%d ", arr[i--]);
   printf(" ");
   fclose(fp);
   return(0);
}

Queation No 2

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
   int arr[20],temp[101],i=0,j=0;
   while(i<20)
   {
       arr[i] = rand() % 101;
       i++;
   }
   i=0;
   printf(" Random numbers.... ");
   while(i<20)
   {
       printf("%d ",arr[i]);
       i++;
   }
   j=0;
   while(j<101)
   {
       temp[j] = 0;
       j++;
   }
   i=0;
   while(i<20)
   {
       temp[arr[i]]=temp[arr[i]] + 1;
       i++;
   }
   i=0;
   printf(" Rundom numbers with counts... ");
   while(i<101)
   {
           printf("Number=%d Count=%d ",i,temp[i]);
       i++;
   }  
return 0;
}