Question

Write a C program Design a program that uses an array to store 10 randomly generated...

Write a C program

Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user:

  1. Display 10 random numbers stored in the array
  2. Compute and display the largest number in the array
  3. Compute and display the average value of all numbers
  4. Exit

The options 2 and 3 should call an appropriate user-defined function and pass the array to the function to compute the largest and the average value respectively. Design and call these two user-defined functions. The average value should be calculated and displayed with a precision of two decimal places.

The program should loop back to the main menu until the user selects the option to exit the program.

Use the register storage class for two the most frequently used variables in your program.

Submit your program's source code (i.e., .c file) and a file with screen captures of your program's.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int lrge(int [],int );
float avge(int [],int );

void main()
{
        register int i; 
        int rand_array[10],ch;
        srand(time(NULL));
        for(i = 0; i<10; i++) 
        rand_array[i]= rand()%50 +1 ; 
    
        printf("\n---------------------------MENU-------------------------\n\n");
                printf("\n1. Display 10 random numbers stored in the array\n\n");
                printf("\n2. Compute and display the largest number in the array\n\n");
                printf("\n3. Compute and display the average value of all numbers\n\n");
                printf("\n4. Exit\n\n");
                
                  
    do
        {    
        printf("\nPlease Enter Your Choice (1 - 4): ");
                scanf("%d", &ch);  
                switch(ch)
                {
                        case 1 :        printf("\nThe Random numbers stored in the array are : ");
                                                for(i=0;i<10;i++)
                                                        printf("%d ", rand_array[i]);   
                                                printf("\n");
                                                break;
                        
                        case 2  :       printf("\nThe largest number in the array is :   %d", lrge(rand_array, 10));
                                                printf("\n");
                                                break;
                        case 3  :       printf("\nThe average value of all numbers :   %.2f", avge(rand_array, 10));
                                                printf("\n");
                                                break;
                        case 4  :       printf("\nThank You. Program is Exiting\n\n");
                                                break;
                        
                }
        
        }
        while(ch!=4);
        
}

int lrge(int ar1[],int n)
{  
    int large=ar1[0];
    static int j;
        for( j=0;j<n;j++)
        {       
                if(ar1[j]>large)
                {
                        large=ar1[j];
                }
                
        }
        return(large);  
}


float avge(int ar1[],int n)
{  
    int sum=0;
    float avg;
    static int j;
        for( j=0;j<n;j++)
        {       
                sum=sum+ar1[j];         
        }
        avg=(float)sum/n;
        return(avg);    
}

--MENU- 1. Display 10 random numbers stored in the array 2. Compute and display the largest number in the array 3. Compute an

Note : Here we are using rand() to generate random number. srand() used generate seed rand() so that it will create different set of random values in each execution.

Add a comment
Know the answer?
Add Answer to:
Write a C program Design a program that uses an array to store 10 randomly generated...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The purpose of this assignment is to get experience with an array, do while loop and...

    The purpose of this assignment is to get experience with an array, do while loop and read and write file operations. Your goal is to create a program that reads the exam.txt file with 10 scores. After that, the user can select from a 4 choice menu that handles the user’s choices as described in the details below. The program should display the menu until the user selects the menu option quit. The project requirements: It is an important part...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Question2 uses structured design implemented in C. Array of records (structs) with file I/O is needed....

    Question2 uses structured design implemented in C. Array of records (structs) with file I/O is needed. The program takes two inputs at a time. The name of a person, and, the coin value as an integer in the range 5 to 95. Input coin values should always be divisible by 5 (integer division). Names are one word strings. An example input is: Jane 30 This input line indicates that 30 cents change is to be given to Jane. Output change...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT