Question

(C PROGRAMMING) Please use arrays// Create a program that presents a menu to the user to:...

(C PROGRAMMING) Please use arrays// Create a program that presents a menu to the user to:
1) enter data
2) print data
3) clear data
0) exit.
Please complete option 3.

Homework Answers

Answer #1

C CODE:

#include <stdio.h>
#include <stdlib.h> //for exit
int main() {
    int n,i; //declaring size variable of array as n and iterator as i
    printf("Enter size of array: ");
    scanf("%d",&n);//input size of array
    int arr[n];//making array
    while(1){ //for infinite loop till exit
    printf("*Press 1 to Enter Data in array \n");
    printf("*Press 2 to Print Data of array \n");
    printf("*Press 3 to Clear Data of array \n");//for clearing data make all 0
    printf("*Press 0 to EXIT  \n");
    int choice;
    scanf("%d",&choice);//inputting choice
    switch(choice)
    {
        case 1:
            printf("\nEnter %d values to insert into array:\n",n);
            for(i=0;i<n;i++)
            {
                scanf("%d",&arr[i]); //inputting values in array
            }
            printf("\n");
            break;
        case 2:
            printf("\nHere are your %d elements of array:\n",n);
            for(i=0;i<n;i++)
            {
                printf("%d ",arr[i]); // outputting array values
            }
            printf("\n\n");
            break;
        case 3:
            for(i=0;i<n;i++)
            {
                arr[i]=0; //clearing values of array by putting 0 at every place
            }
            printf("\nSucessfully cleared data in array:\n\n",n);
            break;
        case 0:
            exit(0); //to exit the program
        default:
            printf("Invalid Input");}} // to handle case other than 0 1 2 
    return 0;}



SCREENSHOT OF C CODE:

SCREENSHOT OF RUNNING PROGRAM:

I hope I solved your query in case of doubt feel free to ask in comment section.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
PLEASE USE IDLE PYTHON: Question (Arrays/Lists) A teacher uses 2   arrays (or Lists) to keep track...
PLEASE USE IDLE PYTHON: Question (Arrays/Lists) A teacher uses 2   arrays (or Lists) to keep track of his students. One is used to store student names and the other stores his grade (0-100). Write a program to create these two arrays (or lists) that are originally empty, and do the following using a menu: 1. Add a new student and his/her grade. 2. Print the name and grade of all current students, one student per line. 3. Display the number...
Write a program that checks the age of a user (C++ Programming)    If the user...
Write a program that checks the age of a user (C++ Programming)    If the user is 18 to 20 print “Sing a song” If the user is younger than 18 then print “Please show a dance step” Else Welcome the user and print “You are audience”
I need the code in C++ not C. please dont forget to create the menu!!!! Create...
I need the code in C++ not C. please dont forget to create the menu!!!! Create a phone book program that allows users to enter names and phone numbers of friends and acquaintances. Create a structure to hold contact information and use to calloc() reserve the first memory segment. The user should be able to add or modify phone book entries through a menu. Use the function to add contiguous memory segments to the realloc() original memory block when a...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for 5 bases and 5 heights (you can use an array), have a function to print the triangle bases, heights, and areas 2. Create a structure for the Triangle that holds the base and height of the triangles. Ask the user for 5 triangles, and print them. 3. Create an array of 5 structures - ask the user for 5 triangles, and then print the...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with...
Problem Statement: Write a Java program “HW6_lastname.java” that prints a program title and a menu with four items. The user should then be prompted to make a selection from the menu and based on their selection the program will perform the selected procedure. The title and menu should be as the following: Student name: <your name should be printed> CIS 232 Introduction to Programming Programming Project 6 Due Date: October 23, 2020 Instructor: Dr. Lomako ******************************** 1.     Compute Angles                               *...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Java Create a new Drive class. * Create a Menu class. * The menu class will...
Java Create a new Drive class. * Create a Menu class. * The menu class will use the previous 4 classes you created in GCD, LCM, FACTORIAL, DIGITS The Menu will display a menu that give you the option of selecting: 1) Greatest Common Denominator 2) Lowest Common Multiple 3) Factorial 4) Number of Digits in an Integer Enter 1,2,3 or 4: When the User enter the choice, then the correct function/method is called for the class and asks the...
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display
Console ================================================================                        Baseball Team Manager MENU OPTIONS 1 – Display lineup 2 – Add player 3 – Remove player 4 – Move player 5 – Edit player position 6 – Edit player stats 7 - Exit program POSITIONS C, 1B, 2B, 3B, SS, LF, CF, RF, P Team data file could not be found. You can create a new one if you want. ================================================================ Menu option: 2 Name: Mike Position: SS At bats: 0 Hits: 0 Mike was added....
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT