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
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:
Get Answers For Free
Most questions answered within 1 hours.