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
What is the result of expression 15 &gt; 10 &gt; 5 in C? What is the result of the same expression in Java?
Inessa05 [86]

Answer:

java: error

C: false

Explanation:

In Java the compiler understand that you are trying to compare an integer (15) with a boolean (10 > 5) this generate the next error:

error: bad operand types for binary operator  

In C the compiler convert (15 > 10 > 5) in (15>10) > (10>5) which is equal to TRUE > TRUE, the compiler can also read it as 1 > 1 (since 1 is TRUE and 0 is FALSE).  like 1>1 is false then C program return false.

5 0
3 years ago
Computer spreadsheet is a grid of​
Kruka [31]
Huh we’re, we’re is the computer screen shot
3 0
3 years ago
Q10: You cannot rename a compressed folder.
user100 [1]
<h2>Answer:</h2><h2>Oh yes you can. </h2>

Click slowly twice the folder.

Right click and choose rename.

4 0
3 years ago
Which of the following are good backup methods you can use to protect important files and folders from loss in the case of a har
grigory [225]

Answer:A,B, and D

Explanation:

6 0
3 years ago
Read 2 more answers
Remote authentication has always been a concern because the person is coming from a public network, and many companies require t
g100num [7]

Answer:

Incomplete Question.

I'll answer this question based on general terms

Explanation:

Two Factor Authentication, abbreviated as 2FA.

It is a type of authentication that requires the presentation of two credentials for access to personal data and information.

The credentials needed for a 2FA are

1. Either of the following; PIN, Password or Pattern

2. Your device or gadget which could be an ATM Card, Mobile Phone

3. Biometrics such as fingerprint, voice input

Number one is often referred to as "Something you know"

Number two is referred to as "Something you have"

Number three is referred to as "Something you are"

The 2FA doesn't require the three aforementioned credentials. It only needs just two of the credentials to provide its authentication.

8 0
4 years ago
Read 2 more answers
Other questions:
  • Professor Zak allows students to drop the four lowest scores on the ten 100 point quizzes she gives during the semester. Design
    13·1 answer
  • A growing number of large organizations have built internal Web sites that provide opportunities for online social networking am
    7·1 answer
  • In cell F15, insert a function that will automatically display the word Discontinue if the value in cell D15 is less than 1500,
    6·1 answer
  • What does it mean when system ui has stopped?
    9·1 answer
  • Which of the following, (1) money deposited in a bank account, (2) student recording her answer to a question in an online test,
    9·1 answer
  • Which communication technology should you use if you need to connect three offices which are all within 3 miles of each other at
    6·1 answer
  • Write a program that inputs numbers and keeps a running sum. When the sum is greater than 100, output the sum as well as the cou
    8·1 answer
  • Write a program that reads 20 integers from the user into an array and uses a function arrayMinimum that accepts an integer arra
    5·1 answer
  • You are a librarian! Ask the user for the last names of the authors of the five books they are returning. Print a list of those
    15·1 answer
  • What does this comparison block indicate?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!