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
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Note: There is a white space in between the numbers. Java programming please answer ASAP before 2:30
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: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...
(Write in C++) Write a program that reads in two numbers and, if the input is...
(Write in C++) Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop...
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...
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers....
Write a Java program named BinaryConversion that will convert base 2 numbers to base 10 numbers. The data for this program will be entered from the keyboard using JOptionPane one 16-bit binary number at a time. Note that each base 2 number is actually read in as a String. The program should continue until a 16-bit base 2 number consisting of all 0’s is entered. Once the 16-bit number has been entered your program should make sure that the input...
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...
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
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...
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....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT