Question

In: Computer Science

Design a program that uses an array to store 10 randomly generated integer numbers in the...

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

Solutions

Expert Solution

#include <stdio.h> 
#include<stdlib.h>
#include<time.h>
void get_maximum(int *arr)
{
        //takes array as argument and displays maximum no from array
        int max=0;
        int i;
        for(i=0;i<10;i++)
        {
                if(arr[i]>max)
                {
                        max=arr[i];
                }
        }
        printf("sum=%d",max);
}
void get_average(int *arr)
{
        //takes array as argument and displays average of array upto 2 decimal point
        int sum=0,i;
        for(i=0;i<10;i++)
        {
                sum+=arr[i];
        }
        float n=10.0;
        float res=sum/n;
        printf("Average=%.2f", res);
}
int main() 
{
        int i,j;
        int arr[10];
    int lower=1,upper=50,count=10;
        srand(time(0)); //current time as seed of random number generator
        for(i=0;i<count;i++)
        {
                int rand_num=(rand() % (lower - upper+ 1)) +lower;//generates random no
                arr[i]=rand_num;        
        }
        int temp=0;
        while(temp==0)
        {
                int user;
                printf("Enter\n");
                printf("1: Display 10 random numbers stored in array:\n");
                printf("2: Largest number in array:\n");
                printf("3: Average value of all numbers:\n");
                printf("4: Exit:\n");
                scanf("%d",&user);
                if(user==1)
                {
                        for(j=0;j<10;j++)//prints array
                        {
                                printf("%d ",arr[j]);
                        }
                }
                else if(user==2)
                {
                        get_maximum(arr);
                        
                }
                else if(user==3)
                {
                        get_average(arr);
                }
                else if(user==4)
                {
                        temp=1;
                }
                else
                {
                        printf("Enter number between 1 and 4:");
                }
                printf("\n");
                
        }
        return 0;
}

Screenshots of the code:

screenshot of the output:


Related Solutions

Write a C program that asks the user to enter 15 integer numbers and then store them in the array.
Write a C program that asks the user to enter 15 integer numbers and then store them in the array. Then, the program will find the second largest element in array and its index without sorting the array. For example, In this array {-55,-2,1, 2, -3, 0, 5, 9, 13, 1, 4, 3, 2, 1, 0}, the second largest element is 9 [found at index 7].
Write a C++ program that uses array to store the salaries of 10 employees working in...
Write a C++ program that uses array to store the salaries of 10 employees working in a small firm. The program should take average of the salaries and the max and min salaries being paid to the employees
Write a program to produce an array of integer random numbers. Your program should find out...
Write a program to produce an array of integer random numbers. Your program should find out from the user how many numbers to store. It should then generate and store that many random integers (the random numbers must be between 1 and 999 inclusive). The program should then determine the smallest number, the largest number, and the average of all the numbers stored in the array. Finally, it should print out all the numbers on the screen, five numbers to...
Create a program in java with the following information: Design a program that uses an array...
Create a program in java with the following information: Design a program that uses an array with specified values to display the following: The lowest number in the array The highest number in the array The total of the numbers in the array The average of the numbers in the array Initialize an array with these specific 20 numbers: 26 45 56 12 78 74 39 22 5 90 87 32 28 11 93 62 79 53 22 51 example...
Design a program that will ask the user to input two integer numbers and then perform...
Design a program that will ask the user to input two integer numbers and then perform the basic arithmetic operations such as addition and subtraction. Each calculation is done by a separate function. The main function gets the input from the user, then calls the addition function and the subtraction function one at a time to perform the calculations. Each calculation function (addition or subtraction function) performs an arithmetic operation and then returns the calculation results back to where it...
Write a C++ program that randomly generates N integer numbers (such that N is entered by...
Write a C++ program that randomly generates N integer numbers (such that N is entered by the user) and then stores them to a text file (myNumbers.txt) sorted in increasing (non-decreasing) order. Again, please notice that the size of the data (N) is known during the run time, not the compile-time (needs to be entered by the user after running the program).
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. I need this in java language.
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. (Write a C# program)
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending...
Radix sortCome up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. I need this in java language. Radix Sort assignment (CISP430 ignore this part) This is only for those who are using Java How many classes do I need? A: Node, Queue, Radix, Driver...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in...
Radix sort Come up with an unsorted array of numbers (integer array). Sort the numbers in ascending order and descending order and display them using radix sort. First sort in ascending, then reset the array to its original order and finally sort the array again in descending order. C++ program thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT