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...
Complete Programming Assignment Chapter 10. Use program In JAVA ProductCodes.java on pages 446-447, it will provide...
Complete Programming Assignment Chapter 10. Use program In JAVA ProductCodes.java on pages 446-447, it will provide you most of the needed code. You are to design and implement a program that reads a series of 10 integers from user and print the average. Read each integer as a string and convert to integer using Integer.parseInt method. If this process throws a NumberFormatException (not a valid number), catch and handle the exception by printing an error message "Not a valid entry,...
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
In this lab, you will write a program that will read a canonical phone number form...
In this lab, you will write a program that will read a canonical phone number form the user, then prints it back to the properly formatted in the for “xxx-xxxx”. You program must achieve the following requirements: 1. If the user enters the number “0”, the program should exit immediately. 2. If the user enters any phone number that is grater than or less than 7-digits, the program should report an error back. In other words, only valid 7-digit numbers...
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 a program that asks the user to guess a random number. The program should use...
Write a program that asks the user to guess a random number. The program should use a loop to prompt the user for the guess then display if the guess is 'too high' or 'too low'. In the end, display how many times it took to guess the number. Use the attached template.   // Chapter 5 - Lab exercise, Random Number Guessing Game // // Name: // #include <iostream> #include <cstdlib> // Needed to use random numbers #include <ctime> //...
(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...
I am to create three different versions of the following C program code below that implements...
I am to create three different versions of the following C program code below that implements the conversion of unsigned binary numbers into decimal (Base 2 to Base 10 conversion). Version 1: Complete the C program ”bin2dec ver1.c” that implements binary to decimal conversion. The maximum number of binary bits is 32. The program is made of the functions ”unsigned binary to decimal(const char *str)”and ”main”. The parameter ”str” passed to this function points to a C string comprising only...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT