Question

Caras → XCO D Question 6 10 pts The program below is intended to traverse a random array, calculate an average and print a fo

intro to c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Note: if you want minimum number need to change num[i] = rand() % 50 + 1; to num[i] = rand() % 5 + 1;

File: intro.c

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
   int i, j, num[4], sum, avg;
   srand(time(0));
   for(i=0; i<4; i++)
       num[i] = rand() % 50 + 1;
  
   sum = num[0] + num[1]+num[2]+num[3];//calculate sum
   avg = sum / 4; //calculate average
   printf("\nSum: %d", sum);//display sum
   printf("\nAverage: %d\n", avg);//display average
   for(i=0;i<avg;i++)//display *
   {
       for(j=0;j<i;j++)
       {
           printf("\t");
       }
       printf("*\n");
   }

   return 0;
}  

Screen:

Add a comment
Know the answer?
Add Answer to:
intro to c Caras → XCO D Question 6 10 pts The program below is intended...
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
  • C PROGRAM ONLY!!! 1). Type a statement using srand() to seed random number generation using variable...

    C PROGRAM ONLY!!! 1). Type a statement using srand() to seed random number generation using variable seedVal. Then type two statements using rand() to print two random integers between (and including) 0 and 9. End with a newline. Ex: 5 7 Note: For this activity, using one statement may yield different output (due to the compiler calling rand() in a different order). Use two statements for this activity. Also, after calling srand() once, do not call srand() again. (Notes) GIVEN:...

  • 9. The purpose of the following program is to generate 10 random integers, store them in...

    9. The purpose of the following program is to generate 10 random integers, store them in an array, and then store in the freq frequency array, the number of occurrences of each number from 0 to 9. Can you find any errors in the program? If yes, correct them. #include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 10 int main(void) int i, num, arr[SIZE], freq[SIZE]; srand (time (NULL)); arr[1] rand(); SIZE; for(i i 〈 i++) num arr[i]; freq[num]++; printf("InNumber occurrences...

  • Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct {...

    Complete the program below in C please #include <stdio.h> #inlcude <stdlib.h> #include <time.h> typedef struct { int points; int strength; } Hero; /* print out the hero given by the parameter */ void printHero( ... ) { . . } void main() { Hero heroA, heroB; /* initialize both heroes to your choice of values */ . /* Pick one hero using rand(). Print out that hero */ . }

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • Using the program segment below, write two short functions to complete the program. Use the test...

    Using the program segment below, write two short functions to complete the program. Use the test cases to ensure the program works properly. Prototypes: void int2bin(int, int[8]); The first function will convert an integer that is between 0 - 255 to its binary representation. You are to store the binary number in the array passed to the function. void printBinary(int[8]); The second function will print the binary number stored in the array passed to the function. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Test 1: 13...

  • My C program is supposed to make a random key the same length of clear_text string...

    My C program is supposed to make a random key the same length of clear_text string and then use the random key to encrypt clear_text, but I can’t get it to work. A wΝΗ 1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<time.h> 4 char* make_rand_key(int length, char* key); 5 void encrypt(); 7- int main() { 8 encrypt(); 9 } 10 char* make_rand_key(int length, char* key){ int range=78; int max=48; char c='a'; int i; 'srand(time(NULL)); for(i=0;i<length;i++){ C=rand()%range_max; key[i]=c; key[i]='\0'; return key; 23...

  • Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a...

    Your task: 1. Study Slides 24 -28 of “FunctionCalling.pptx” 2. Answer the following question in a separate file, called “Assignment#4.pdf”: • Show all the possible outcomes of the experiment (rolling the dice) using a 2-D table. (see Slides 26, 27) • What are the events (possible sums) such as 2, 3, … (See Slide 26, 27). Example: Number Distribution so Generating numbers that conform a given distribution so Create an array to store all possible outcomes. int twodices[OUTCOME ]={2,3,4,5,6,7, 3,4,5,6,7,8,...

  • C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion:...

    C++ Program - Arrays- Include the following header files in your program:     string, iomanip, iostream Suggestion: code steps 1 thru 4 then test then add requirement 5, then test, then add 6, then test etc. Add comments to display assignment //step 1., //step 2. etc. This program is to have no programer created functions. Just do everything in main and make sure you comment each step. Create a program which has: 1. The following arrays created:                 a. an array...

  • Writing a program in C please help!! My file worked fine before but when I put...

    Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...

  • Prime Number Programing in C Note: The program is to be written using the bitwise operation....

    Prime Number Programing in C Note: The program is to be written using the bitwise operation. Use an integer array (not a Boolean array) and a bit length (for instance 32 bits). In this program you will write a C program to find all prime numbers less than 10,000. You should use 10,000 bits to correspond to the 10,000 integers under test. You should initially turn all bits on (off) and when a number is found that is not prime,...

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