Write a program in C language. Project: list management Goal: Creating, updating
ID: 3851651 • Letter: W
Question
Write a program in C language. Project: list management Goal: 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 and 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. 1. Adding any amount of numbers to myList 2. Removing all occurrences of a selected number from myList 3. Finding and displaying the maximum, minimum and range (maximum-minimum) in myList 4. Finding the number of occurrences of a number in myList 5. doubling, (multiplying by 2) all numbers in myList 6. display all members of myList 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 a[])
{
int i;
time_t t;
srand((unsigned) time(&t));
for( i = 0 ; i < 10 ; i++ )
{
a[i]=rand();
}
}
int q=100;
void func1(int a[])
{
int k,i,l;
printf("Enter how many numbers you want to add");
scanf("%d",&k);
for(i=0;i<k;i++)
{
a[q++]=rand();
}
}
void func2(int a[])
{
int i,n;
printf("Enter number ");
scanf("%d",&n);
for(i=0;i<q;i++)
{
if(a[i]==n)a[i]=-1;
}
}
void func3(int a[])
{
int i,max=0,min=9999999;
for(i=0;i<q;i++)
{
if(a[i]>max)max=a[i];
if(a[i]<min)min=a[i];
}
printf("max = %d and min = %d ",max,min);
}
void func4(int a[])
{
int i,n,count=0;
printf("Enter number ");
scanf("%d",&n);
for(i=0;i<q;i++)
{
if(a[i]==n)count++;
}
printf("This number occurs %d times ",count);
}
void func5(int a[])
{
int i,n;
for(i=0;i<q;i++)
{
a[i]=2*a[i];
}
}
void func6(int a[])
{
int i,n;
for(i=0;i<q;i++)
{
printf("%d ",a[i]);
}
}
void main()
{
int myList[1000],n;
FirstElements(myList);
while(1)
{
printf(" 1. Add numbers to myList 2. Remove all occurrences of a number 3. Display max min 4. Find number of occurrences 5. Double 6. Display all 7. Quit");
scanf("%d",&n);
if(n==1)
{
func1(myList);
}
else if(n==2)
{
func2(myList);
}
else if(n==3)
{
func3(myList);
}
else if(n==4)
{
func4(myList);
}
else if(n==5)
{
func5(myList);
}
else if(n==6)
{
func6(myList);
}
else if(n==7)
{
exit(0);
}
printf("Press Y for new request or Q to quit ");
char d;
d=getch();
if(d=='q'||d=='Q')exit(0);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.