Question

USE ONLY C LANGUAGE The program should read inputs that look like this: 10 11 56...

USE ONLY C LANGUAGE

The program should read inputs that look like this:

10

11 56 92 10 5 42 7 1 33 99

The program should start by reading one integer, which indicates how many numbers there are in the random sequence. The program should then read a sequence of random integers. If fewer numbers are provided than specified (by the first integer on the first line), the program should print the following error message (replace XXX with the number of integers expected and YYY with the number of integers you were able to read) and exit: XXX numbers are required, but only YYY were provided. If any number provided is outside the range specified the program should print the following error message (replace XXX with the incorrect number you read) and exit: XXX is not in the [0, 99] range. Each number generated falls into one of 10 bins: – Numbers between 0 and 9 – Numbers between 10 and 19 – Numbers between 20 and 29 – … – Numbers between 90 and 99 • Count how many of the generated numbers fall in each bin.

use only - #include stdio.h #include stdlib.h #include math.h #include assert.h #include time.h

Homework Answers

Answer #1

PROGRAM:


#include <stdio.h>

int main()
{
  
int n;
printf("enter how many numbers there are in the random sequence");
scanf("%d",&n);
int seq[10];
for(int i=0;i<n;i++){
seq[i]=-1; //initializing minimum false value in array of sequence
}
  
for(int j=0;j<n;j++){
scanf("%d",&seq[j]);
}
int x=0,y=0;
for(int k=0;k<n;k++){
if(seq[k]<0){
x++; //counting x's
}
else{y++;}
}
if(x>0){
for(int l=0;l<x;l++){
printf("X");
}
printf(" numbers are required, but only ");
for(int h=0;h<y;h++){
printf("Y");
}
printf(" were provided\n");
}
int count_range=0;
int bins[10]; //creating count array for elements falling in particular range
if(x<=0){
for(int g=0;g<10;g++){
if(seq[g]<0 || seq[g]>99){
count_range++;
}
}
if(count_range>0){
for(int d=0;d<count_range;d++){
printf("X");
}
printf(" is not in the [0, 99] range \n");
}
else{
for(int a=0;a<10;a++){
bins[a]=0; //initializing bins with 0
}
for(int b=0;b<n;b++){
if(seq[b]>=0 && seq[b]<=9){
bins[0]++; //increasing counter of each bin
}
else if(seq[b]>=10 && seq[b]<=19){
bins[1]++;
}
else if(seq[b]>=20 && seq[b]<=29){
bins[2]++;
}
else if(seq[b]>=30 && seq[b]<39){
bins[3]++;
}
else if(seq[b]>=40 && seq[b]<=49){
bins[4]++;
}
else if(seq[b]>=50 && seq[b]<=59){
bins[5]++;
}
else if(seq[b]>=60 && seq[b]<=69){
bins[6]++;
}
else if(seq[b]>=70 && seq[b]<=79){
bins[7]++;
}
else if(seq[b]>=80 && seq[b]<=89){
bins[8]++;
}
else if(seq[b]>=90 && seq[b]<=99){
bins[9]++;
}
}
printf("count of no. falling in range 0 to 9 : %d \n",bins[0]);
printf("count of no. falling in range 10 to 19 : %d \n",bins[1]);
printf("count of no. falling in range 20 to 29 : %d \n",bins[2]);
printf("count of no. falling in range 30 to 39 : %d \n",bins[3]);
printf("count of no. falling in range 40 to 49 : %d \n",bins[4]);
printf("count of no. falling in range 50 to 59 : %d \n",bins[5]);
printf("count of no. falling in range 60 to 69 : %d \n",bins[6]);
printf("count of no. falling in range 70 to 79 : %d \n",bins[7]);
printf("count of no. falling in range 80 to 89 : %d \n",bins[8]);
printf("count of no. falling in range 90 to 99 : %d \n",bins[9]);
}
}
return 0;
}

CODE SCREENSHOT:

CODE OUTPUT:

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
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas,...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas, the following les for each of your programs: (1) the client and the server source les each (2) the client and the serve executable les each (3) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identiers suitable, to enable enhanced readability of the code. Problems 1. Write an ftp client that...
In this example you are allowed to use from the C standard library only functions for...
In this example you are allowed to use from the C standard library only functions for input and output (e.g. printf(), scanf()) Complete the following functions using C programming language: A positive integer number is said to be a perfect number if its positive factors, including 1 (but not the number itself), sum to the number. For example, 6 is a perfect number because 6=1+2+3. Complete the int Q6(intQ6_input, int perfect[])function that determines all perfect numbers smaller than or equal...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Question Recursive Maximum: In this question you must develop and use a recurive function to find...
Question Recursive Maximum: In this question you must develop and use a recurive function to find the maximum value in array of integers. Complete the C program, Maximum.c, by implementing the recursive function maximumValue, and the regular function max, and completing the main function using the comments provided. Open the file Maximum.c, complete, compile and run it. When you are sure it is correct, include the c file in your final submission. Note that the function max is not recursive....
C LANGUAGE CODE WITH COMMAND-LINE ARGUMENTS (NO SCANF TO BE USED ) Q]. Write a program...
C LANGUAGE CODE WITH COMMAND-LINE ARGUMENTS (NO SCANF TO BE USED ) Q]. Write a program that displays all the prime numbers in the given array with the following constraint. Constraint: Only those prime numbers should be displayed whose location is a composite number. Although you may have several prime numbers in the array, only those prime numbers should be displayed which are stored at non-prime locations. Remember that the first position in an array corresponds to the location/index 0....
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on...
Lottery The lottery game matches three different integer numbers between 1 and 10. Winning depends on how many matching numbers are provided by a player. The player provides three different integers between 1 and 10. If there is a match of all 3 numbers, the winning $ 1000. If there is a match with 2 numbers, the winning $ 10. If there is a match with 1 number, the winning $ 1. With no match, the winning is $0. Write...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the...
Written in MASM Assembly Problem Definition: Write a program to calculate Fibonacci numbers. • Display the program title and programmer’s name. Then get the user’s name, and greet the user. • Prompt the user to enter the number of Fibonacci terms to be displayed. Advise the user to enter an integer in the range [1 .. 46]. • Get and validate the user input (n). • Calculate and display all of the Fibonacci numbers up to and including the nth...
Design ONE FUNCTION in a C++ code to find minimum, maximum and average of items in...
Design ONE FUNCTION in a C++ code to find minimum, maximum and average of items in an array, then place them proper locations in the array. Follow these steps: 1. Create an array with 11 integers, which will be randomly selected from the range of 10 to 100. Only random numbers between 10 and 100 are allowed in the array. Print the items of the array on screen as one line. 2. Develop a function that takes the array as...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT