1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vagabundo [1.1K]
3 years ago
13

Write a C program that stores N random numbers in an array named rA[ ] and determine the largest, smallest, and average values o

f this array. Display the array elements that store these values. The random numbers range from -50 to +50. N is a command line argument.
Computers and Technology
1 answer:
Aliun [14]3 years ago
4 0

Answer:

// program in C.

// headers

#include <stdio.h>

// headers

#include <stdlib.h>

// headers

#include <limits.h>

// main function

int main(int argc, char** argv)

{

   // read value of N from command line arguments

   int N=atoi(argv[1]);

   // variables

   int max=INT_MIN;

   // variable

   int min=INT_MAX;

int rA[N],i;

// fill the array with random number

for(i=0;i<N;i++)

{

    // generate random number from -50 to +50

    rA[i]=rand()%101-50;

    // find the Maximum

    if(rA[i]>max)

    max=rA[i];

    // find the Minimum

    if(rA[i]<min)

    min=rA[i];

}

// print values of array

printf("values of the array are:");

for(i=0;i<N;i++)

{

    printf("%d ",rA[i]);

}

// print Maximum

printf("\nMaximum value is:%d",max);

// print Minimum

printf("\nMinimum value is:%d",min);

return 0;

}

Explanation:

Read value of N from command line.Then create an array of size N.Fill the array with random number from -50 to +50.Then find the Maximum of all the elements and  assign it to variable "max" and find Minimum from all and assign it to variable "min". then print all the elements of the array, Minimum and Maximum.

Output:

command line argument=10

values of the array are:-18 -18 4 -38 2 6 -42 -20 -6 44 -6 -11 15 -31 1                                                    

Maximum value is:44                                                                                                        

Minimum value is:-42

You might be interested in
Write a static method that implements a recursive formula for factorials. Place this method in a test program that allows the us
matrenka [14]

Answer:

Written in Java

import java.util.*;

public class Main {

  public static int fact(int n) {

     if (n == 1)

        return n;

     else

        return n * fact(n - 1);

  }

  public static void main(String[] args) {

     int num;

     Scanner input = new Scanner(System.in);

     char tryagain = 'y';

     while(tryagain == 'y'){

     System.out.print("Number: ");

     num = input.nextInt();

     System.out.println(num+"! = "+ fact(num));

     System.out.print("Try another input? y/n : ");

     tryagain = input.next().charAt(0);

}        

  }

}

Explanation:

The static method is defines here

  public static int fact(int n) {

This checks if n is 1. If yes, it returns 1

     if (n == 1)

        return n;

If otherwise, it returns the factorial of n, recursively

     else

        return n * fact(n - 1);

  }

The main method starts here. Where the user can continue executing different values of n. The program keep prompting user to try again for another number until user signals for stoppage

  public static void main(String[] args) {

This declares num as integer

     int num;

     Scanner input = new Scanner(System.in);

This initializes tryagain as y

     char tryagain = 'y';

This checks if user wants to check the factorial of a number

     while(tryagain == 'y'){

This prompts user for input

     System.out.print("Number: ");

This gets user input

     num = input.nextInt();

This passes user input to the function and also prints the result

     System.out.println(num+"! = "+ fact(num));

This prompts user to try again for another value

     System.out.print("Try another input? y/n : ");

This gets user response

     tryagain = input.next().charAt(0);

}        

Download txt
4 0
2 years ago
What is a frame injection attack in a wireless network?
Romashka-Z-Leto [24]

Answer:

A.Un hacker introduce un cadru fals în timpul transmiterii datelor.

Explanation:

3 0
3 years ago
Read 2 more answers
How do you strike through text in excel?
Valentin [98]
In the font options there is a checkbox for strikethrough. Same dialog as word, only there is no button in the ribbon for it. You could customize that by creating a custom group if you want to.
6 0
3 years ago
this is a question about this app. Is the plus a scam or something. please tell me the truth. cause ive paid for it and it worke
mylen [45]
I didn’t get the plus and it let me review answers without an ad so idk so like you really don’t need plus I wouldn’t get it
7 0
3 years ago
Read 2 more answers
How is a LCD screen and view finder similar?
dem82 [27]

Answer:

LCD screens have advantages, but so do optical viewfinders. ... Unlike the optical viewfinder, the LCD screen displays the entire frame that the sensors capture. Optical viewfinders, even on a professional level DSLR, only show 90-95% of the image. You lose a small percentage on the edges of the image.

Explanation:

6 0
3 years ago
Other questions:
  • All formulas that begin with =IF will
    5·1 answer
  • Create a program the outputs the total cost of a lunch order. Users should be prompted to input the number of hamburgers, fries,
    6·1 answer
  • What is the most powerful gpu or known as the graphics card in the world?
    8·2 answers
  • What is the magnitude of the largest positive value you can place in a bool? a char? an int? a float? a double??
    8·1 answer
  • A pedometer treats walking 2,000 steps as walking 1 mile. Write a program whose input is the number of steps, and whose output i
    15·2 answers
  • Different video files and ______ can cause compatibility issues to arise between computer systems.
    8·1 answer
  • The Harrison Group Life Insurance company computes annual policy premiums based on the age the customer turns in the current cal
    5·1 answer
  • What will be the results from running the following code?
    5·1 answer
  • What is the name of the programming language created by Spu7Nix?
    13·2 answers
  • HELP ME PLEASE
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!