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

C++ programing, please copy paste the code. Write a program that generates an ar

ID: 3719620 • Letter: C

Question

C++ programing, please copy paste the code.

Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit


C++ programing, please copy paste the code.

Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit




Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit


Write a program that generates an array filled up with random positive integer number ranging from 15 to 20, and display it on the screen. After the creation and displaying of the array , the program displays the following: [P]osition [R]everse, [A]verage, [S]earch, [Q]uit


Explanation / Answer

Hi,

Please find my working code.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main()
{
int arr[10],i,temp,j,sum=0;
int find,count=0;
float avg;
char ch;
srand(0);
printf(" **Random Number array** ");
for(i=0;i<10;i++)
{
   arr[i]=14+rand()%10;
   printf("%d ",arr[i]);
}
while(1)
{
   printf(" Enter your choice: P. Position R. Reverse A. Average S. Search Q. Quit");
   scanf(" %c",&ch);
   if(ch=='q' || ch=='Q') break;
   switch (ch)
   {
   case 'p':
   printf(" Array Element postion ");
   for(i=0;i<10;i++)
   {
       printf(" %d. %d",i,arr[i]);
   }
   break;
   case 'P':
   printf(" Array Element postion ");
   for(i=0;i<10;i++)
   {
       printf(" %d. %d",i,arr[i]);
   }
   break;
   case 'r':
       j=i-1;
       i=0;
   while(i<j)
   {
       temp=arr[i];
       arr[i]=arr[j];
       arr[j]=temp;
       i++;
       j--;
   }
   printf(" Reverse array ");
   for(i=0;i<10;i++)
   printf("%d ",arr[i]);
   break;
   case 'R':
   j=i-1;
       i=0;
   while(i<j)
   {
       temp=arr[i];
       arr[i]=arr[j];
       arr[j]=temp;
       i++;
       j--;
   }
   printf(" Reverse array ");
   for(i=0;i<10;i++)
   printf("%d ",arr[i]);
   break;

   case 'a':
       printf(" Average of array is:");
       for(i=0;i<10;i++)
       sum=sum+arr[i];
       avg=(float)sum/10;
       printf("%f",avg);
   break;
   case 'A':
       printf(" Average of array is:");
       for(i=0;i<10;i++)
       {
       sum=sum+arr[i];
       }
       avg=(float)sum/10;
       printf("%f",avg);
   break;
   case 's':
       printf(" Enter Number to search in array:");
       scanf("%d",&find);
       for(i=0;i<10;i++)
       {
           if(arr[i]==find)
           {
               printf(" %d is present at location %d",find,i);
               count++;
           }
       }
       if(count==0)
       printf(" %d is not present in array");
       else
       printf(" %d is present %d times in array.",find,count);
   break;
   case 'S':
       printf(" Enter Number to search in array:");
       scanf("%d",&find);
       for(i=0;i<10;i++)
       {
           if(arr[i]==find)
           {
               printf(" %d is present at location %d",find,i);
               count++;
           }
       }
       if(count==0)
       printf(" %d is not present in array");
       else
       printf(" %d is present %d times in array.",find,count);
   break;
}
}
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