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

Write a program which create, an array of SIZE 25. Fu.xtlo.tt are not rw^Ued. 1.

ID: 3681362 • Letter: W

Question


Write a program which create, an array of SIZE 25. Fu.xtlo.tt are not rw^Ued. 1. Use a/or loop to populate this array with 25 random number* between 1000 VlnOuv^Y Output these elements to screen and tile "statstxt'. Calculate and output to We "statstxt". the maximum value for these 25 elements label appropriately 2. Use a while loop to populate this array with 25 random numbers between 4COG-10COQ (inclusive). Output these elements to screen and lile "stats.txt* Calculate and output toTOe "stats.txt", the averaRg value for these 25 elements. Label appropriately. 3. Plsce your name and the date at the top o>> the output screcn. and at the top o

Explanation / Answer

Program which generates the random numbers between 1 to 1000 using forloop

#include <stdio.h>
int main(){
   int i;
   FILE *fptr;
fptr=(fopen("C:\stats.txt","w"));
int seedVal=1;
   //t is a 'time_t' type variable
   time_t t;
seedVal = (unsigned) time (&t);
srand(seedVal);

int array[25];
for(i=1;i<=25;i++)
{
   array[i]=rand() % 1000+1;
   }

/* Print random numbers between 1 to 1000 */
int max=array[0];
printf("Williams ");
printf("Today's date and time : %s",ctime(&t));
printf("The Random Numbers are :: ");
fprintf(fptr,"Williams");
fprintf(fptr,"Today's date and time : %s",ctime(&t));
fprintf(fptr,"The Random Numbers are :: ");
for(i=1;i<=25;i++)
{
   printf("%d ",array[i]);
   fprintf(fptr," %d ",array[i]);
   if(max<array[i])
       {
           max=array[i];
       }
      
   }
   fprintf(fptr," The Maximum value among these numbers is :: %d",max);
   printf("The Maximum value among these numbers is ::%d",max);
fclose(fptr);
return 0;
}

--------------------------------------------------------------------------------------------------------------------------------------------------------

Program which generates the random numbers between 4000 to 10000 using whileloop

#include <stdio.h>
int main()
{
   int seedVal=4000;
   //t is a 'time_t' type variable
   time_t t;
seedVal = (unsigned) time (&t);
srand(seedVal);
  
   int i=1,average,sum=0;
   int j=0;
   FILE *fptr;
fptr=(fopen("C:\stats.txt","w"));
  

int array[25];
while(i<=25)
{
   array[j]=rand() % 10000+1;
   sum=sum+array[j];
   j++;i++;
   }
average=sum/25;
/* Print random numbers between 4000 to 10000 */
printf("Williams ");
printf("Today's date and time : %s",ctime(&t));
printf("The Random Numbers are :: ");
fprintf(fptr,"Williams");
fprintf(fptr,"Today's date and time : %s",ctime(&t));
fprintf(fptr,"The Random Numbers are :: ");
int k=0,l=1;
while(l<=25)
{
   printf("%d ",array[k]);
   fprintf(fptr," %d ",array[k]);
l++;
       k++;
   }
   fprintf(fptr," The Average of these Random Numbers is :: %d",average);
   printf("The Average of these Random Numbers is ::%d",average);
  
fclose(fptr);
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