1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Luda [366]
3 years ago
7

(C Language) Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representa

tion of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...".
The program will ask the user to enter a non-zero positive number. Using a while loop, validate that the number is not greater than 40, and if so, re-ask for the number. Put the entire program into a sentinel-controlled loop so that the user can enter either zero (0) or a negative number to end the program.

Create constants for 1 (the minimum number for the histogram), and 40 (the maximum number for the histogram), and use these constants in the prompts, the validation condition and error message, and the sentinel-controlled loop and the histogram loop.

Hints:

Validation messages are indented 3 spaces
You can use either a pre-test loop (with the initial prompt outside the loop, and the re-prompt at the end of the loop) or a post-test loop (with the prompt inside the loop, and a decision to print the histogram also inside to loop).
Coded the histogram using a for loop (although any type of loop could be used)
Example Run:

(bold type is what is entered by the user)

Enter a non-zero positive number less than 40: 5
***** 5

Enter another non-zero positive number less than 40: 48
The number entered was greater than 40.
Please re-enter: 8
******** 8

Enter another non-zero positive number less than 40: -1

Bye...

The example run shows EXACTLY how your program input and output will look.
Computers and Technology
1 answer:
Kobotan [32]3 years ago
3 0

Answer:

Explanation:

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You

=================================

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>

int main() {

  //Declaring constants

const int MIN=1;

  const int MAX=40;

 

  //Declaring variables

  int num,i;

      printf("Enter a non-zero positive number less than 40: ");  

     

     

/* This while loop continues to execute

* until the user enters a number <=0

*/

  while(1)

  {

      scanf("%d",&num);

      if(num<=0)

      {

          break;

      }

      else if(num>40)

      {

      printf("The number entered was greater than %d.\n",MAX);

          printf("Please re-enter: ");

      }

      else

      {

          for(i=0;i<num;i++)

          {

              printf("*");

          }

          printf("%d\n",num);

          printf("Enter another non-zero positive number less than 40: ");

      }

         

  }

 

  printf("bye...");

  return 0;

 

}

================================

output:

Enter a non-zero positive number less than 40:5

*****5

Enter another non zero positive number less than 40: 48

The number entered was greater than 40.

please Re-enter: 8

********8

Enter another non zero positive number less than 40: 1

bye...

---------------------------------------------

Process exited after 15.48 seconds with return value 0

Press any key to continue.......

You might be interested in
Consider the system of simultaneous equations:
FromTheMoon [43]

Answer:

System of linear equations is solved below and explained in detail.

Explanation:

Part a:

M = [1  3  5  2; 2  -4  7  -3; 0  -4  -7  3; 5  -3  2  1];

c =  [7;  -3;  -1;  0];

Part b:

The statement used for the solution of system of linear equation will be:

X = linsolve(M,c)

where X will give the values of x1, x2, x3, x4 respectively.

Part c:

The system is solved in matlab using above equation and the results are attached in a file.

The values for X are:

x1 = -2/7

x2 = 3/7

x3 = 4/7

x4 = 11/7

4 0
3 years ago
Please help ASAP!
makkiz [27]
B. training is the correct answer
8 0
2 years ago
In the electric series, which one of the following materials is the most negatively charged? A. Silk B. Sealing wax C. Teflon D.
Snowcat [4.5K]
C) Teflon (:


Good luck!
7 0
4 years ago
Read 2 more answers
The main trade-off that all investors must consider is
Talja [164]
<span>The main trade-off that all investors must consider is Risk vs Return
In the end, all the techniques that implemented in investing process is aimed for nothing other than profit.
Current market trend dictates that potential return tend to be higher the riskier the investment is and vice versa.
</span>
3 0
3 years ago
Read 2 more answers
To add a glow effect to WordArt text, which of the following should be done?
g100num [7]
Number 2 is the correct answer
8 0
3 years ago
Other questions:
  • Ned and mary ann are saving their files to a cd
    15·1 answer
  • Hot five was the famous band of which musician?
    14·1 answer
  • Remy’s manager has asked him to change the background color scheme from reds to blues in the standard template the company uses
    15·2 answers
  • An optimal solution to a linear programming problem MUST lie A. somewere on the line between two corner points. B. somewhere out
    12·1 answer
  • Write a CPP Program to read an integer number. Use a pointer to display this numbe
    5·1 answer
  • What is the name for a hardcoded value entered into a formula ?
    8·2 answers
  • Operating systems provide a measure of security by allowing users to access to those resources they've been cleared to use as we
    8·1 answer
  • Laptop computers use PCMCIA cards, another type of ________
    15·1 answer
  • Modern life is not possible if computer stops working? Give your opinion<br>​
    7·1 answer
  • Which are ways that technology keeps you hooked?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!