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]
4 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]4 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
Briefly explain the importance of doing backup in systems administration and explain in detail any three methods for performing
Dmitry_Shevchenko [17]

Answer:

Importance of backup in system administration:

Backups are crucial in system administrations for preserving continuity and protecting against specific types of hardware failures, service interruptions, and human mistakes. To aid a company in recovering from an unexpected catastrophe, backup copies make it possible to restore data to a previous point in time. To safeguard against primary data loss or corruption, it is essential to save a copies of data on a different media. When a system administrator create a backup, he makes a copy of the data that you can restore if your main data is lost. These errors may be the consequence of faulty hardware or software, corrupted data, or a human error like a targeted attack or an unintentional deletion. System backup and recovery is therefore a crucial skill for system administrators as well as the companies they work for.

Three methods for performing backup:

  1. Disk image: A efficient method to back up not only the files and directories but also everything else on the system is by creating a disk image. If a user have a disk image, the user can restore everything, including the operating system, applications, data, and more, so the user won't have to worry about any difficulties. Placing the  disk image-containing DVD into the DVD-ROM to restore the backup. Additionally, just attach an external HDD to the computer if the user have a disk image that they made.
  2. External hard drive: The most common backup method is to use an external hard drive or even a USB flash drive. An HDD can be easily, quickly, and affordably backed up. It is effective since consumers may carry their portable backup with them wherever they go.
  3. Cloud backup: Cloud backup or Online backup has been around for a while, but not many people really utilize it. But the greatest backup technique by far is cloud backup. The user does not have to worry about hardware problems because their files are saved in the cloud and can be accessed from anywhere because the backups are automatically produced and everything is synchronized. It is one of the greatest methods to backup, especially when you consider that the contents are encrypted and stored securely.

6 0
2 years ago
What pressure will be shown on the high side peessure gauge (ac system on)
maria [59]
H tht would be the correct answer
8 0
4 years ago
1.) An education application would most likely do which of the following?
77julia77 [94]
The answer would be D teach a new language.
3 0
4 years ago
Read 2 more answers
According to the word entry, how many definitions are there for the word syllable
Anarel [89]
: a unit of spoken language that is next bigger than a speech sound and consists of one or more vowel sounds alone or of a syllabic consonant alone or of either with one or more consonant sounds preceding or following

2: one or more letters (such as syl, la, and ble) in a word (such as syl*la*ble) usually set off from the rest of the word by a centered dot or a hyphen and roughly corresponding to the syllables of spoken language and treated as helps to pronunciation or as guides to placing hyphens at the end of a line

3: the smallest conceivable expression or unit of something : JOT

4: SOL-FA SYLLABLES

3 0
3 years ago
What determines whether you can run two programs at the same time or connect your computer to a network?
GuDViN [60]
How your computer is built. Processor... Wireless card.... network card... ethernet ports...
4 0
4 years ago
Other questions:
  • What's a good show to watch on Netflix?
    7·1 answer
  • You have an old photograph that you want to incorporate in a brochure for your antique business. To convert the photo into digit
    9·2 answers
  • What is autofill in a excel spreadsheet?
    7·1 answer
  • Ross has to create a presentation for his class but can't decide on a topic. What should he do?
    9·2 answers
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • I'm using assembly language. This is my assignment. I kinda confused about how to write code for this assignment. Can anyone exp
    11·1 answer
  • Describe the characteristics of a mesh network.
    13·1 answer
  • You should always try to avoid showing that an animal in a zoo is a captive animal. True False
    5·1 answer
  • This seems like a good time to ask the basic question, “How’s it going in class?” Feel free to offer constructive feedback about
    6·2 answers
  • It's in Python, everything sort of explained in the image below,
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!