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

Write a function called FirstElements for adding 100 random integers between 100

ID: 3851671 • Letter: W

Question

Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList. using C program

Project: List management Goa l: creating, updating and displaying a list using a menu. Instruction: Create an array called myList. Write a function called FirstElements for adding 100 random integers between 100 to 1000 to myList Initialize the first 100 elements of myList by calling the FirstElements function. Create a menu to display the following options and a number corresponding to each option which is used for selecting the desired option: Create a menu to dihefolwing ootions and a number 1- adding any amount of numbers to myList o 2-removing all occurrences of a selected number from myList o 3- finding and displaying the maximum, minimum and range (maximum-minimum) in myList o 4- finding the number of occurrences of a number in myList o5- doubling (multiplying by 2) all numbers in myList o 6- display all members of myList. o 7- quit for each menu item create a function. when the item number is typed, the function should be executed, the required inputs should be requested, and the proper output should be produced. the outputs can be formatted in a proper fashion of your choice after executing any function in the menu, the user should be given the choice to select another menu or quit (Y for the new request and Q for quit). · if the user has a new request, the menu should appear again and the process repeated.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
void FirstElements(int *array)
{
   int i=0;
   for(i=0;i<100;i++)
   array[i]=100+rand()%(1000-100);  
}

int Add(int *myList,int i)
{
   int x=0;
       printf(" Enter the number to be added : ");
           scanf("%d",&x);
           myList[i++]=x;
           printf(" ");
           return i;
}


int Delete(int *myList,int i)
{
   int s=0,k=0,flag=0;
       printf(" Enter the number to be deleted : ");
           scanf("%d",&s);
           for(k=0;k<i;k++)
           {
               if(myList[k]==s){
               myList[k]=0;
               flag=1;
               }
              
           }
          
           if(flag==0)printf(" Number not found");
           printf(" ");
           printf(" ");
           return i;
}

int MaxMin(int *myList,int i)
{
   int min=0,max=0,k=0;
   min=myList[0];
   max=myList[0];
  
   for(k=0;k<i;k++)
           {
               if(myList[k]>max) max=myList[k];
               if(myList[k]<min) min=myList[k];
           }
           printf(" Maximum=%d, Minimum=%d, Range=%d",max,min,max-min);
           printf(" ");
           return i;
}


int Search(int *myList,int i)
{
   int k=0,s=0,flag=0;
       printf(" Enter the number to be searched : ");
           scanf("%d",&s);
           for(k=0;k<i;k++)
           {
               if(myList[k]==s){
               printf(" Number found at %d place in myList",k+1);
               flag=1;  
               }
              
           }
           if(flag==0)printf(" Number not found");
           printf(" ");
   return i;
}


int Double(int *myList,int i)
{
   int k=0;
           for(k=0;k<i;k++)
           {
               myList[k]=2*myList[k];
           }
              
   return i;      
}

int Print(int *myList,int i)
{
   int k=0;
       printf(" myList is : ");
               for(k=0;k<i;k++)
           {
               printf(" myList[%d]=%d",k+1,myList[k]);
           }
           printf(" ");
           return i;
}
int main()
{
   int i=0,p=0;
   int myList[10000]={0};
   FirstElements(myList);  
   i=100;
   char ch[2]={'Y',''};
   while(p!=7)
   {
      
       printf("Press 1 to add number to myList");
       printf(" Press 2 to remove all occurences of a seleted number from myList");
       printf(" Press 3 to display maximum, minimum and range in myList");
       printf(" Press 4 to find the number of occurences of a number in myList");
       printf(" Press 5 to doubling all the numbers in myList");
       printf(" Press 6 to display all the members of myList");
       printf(" Press 7 to Quit");
       printf(" Enter your choice : ");
       scanf("%d",&p);
       if(p==1)
       {
           i=Add(myList,i);      
       }
       else if(p==2)
       {
           i=Delete(myList,i);  
       }
       else if(p==3)
       {
           i=MaxMin(myList,i);
       }
       else if(p==4)
       {
           i=Search(myList,i);
       }
      
       else if(p==5)
       {
           i=Double(myList,i);
       }
       else if(p==6)
       {
           i=Print(myList,i);
       }
       else if(p==7)
       {
           exit(1);
       }
       else if(p>=8 && p<1)
       {
           printf(" Wrong Choice of p Entered");
       }
      
       printf(" Press Y for new request or Q to exit :");
       scanf("%s",&ch);
       while(ch[0]!='Y'){
      
       if(ch[0]=='Q')
       exit(1);
       else if (ch[0]=='Y')break;
      
       printf(" Press Y for new request or Q to exit :");
       scanf("%s",&ch);
       }
   }
   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