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
QveST [7]
2 years ago
7

In c please

Computers and Technology
1 answer:
Paraphin [41]2 years ago
5 0

Answer:

#include <stdio.h>

#include <ctype.h>

void printHistogram(int counters[]) {

   int largest = 0;

   int row,i;

   for (i = 0; i < 26; i++) {

       if (counters[i] > largest) {

           largest = counters[i];

       }

   }

   for (row = largest; row > 0; row--) {

       for (i = 0; i < 26; i++) {

           if (counters[i] >= row) {

               putchar(254);

           }

           else {

               putchar(32);

           }

           putchar(32);

       }

       putchar('\n');

   }

   for (i = 0; i < 26; i++) {

       putchar('a' + i);

       putchar(32);

   }

}

int main() {

   int counters[26] = { 0 };

   int i;

   char c;

   FILE* f;

   fopen_s(&f, "story.txt", "r");

   while (!feof(f)) {

       c = tolower(fgetc(f));

       if (c >= 'a' && c <= 'z') {

           counters[c-'a']++;

       }

   }

   for (i = 0; i < 26; i++) {

       printf("%c was used %d times.\n", 'a'+i, counters[i]);

   }

   printf("\nHere is a histogram:\n");

   printHistogram(counters);

}

You might be interested in
1D Array Assignment Outcome: Student will demonstrate the ability to use a one-dimensional array. Student will demonstrate the a
sukhopar [10]

Answer:

Program to this question as follows:

program:

import java.util.*; //import package for user input

public class Main  //defining class  

{

public static void main(String[] as)//defining main function

{//defining integer array

int [] num = new int[113];  

boolean find_in = false; //defining boolean variable

int [] counts = new int[101];//defining integer array

int y, tem = 0, counter = 0,in=0,x,find; //defining integer variable

Scanner ox= new Scanner(System.in); //creating Scanner class Object

while(counter <= 112) //loop to check condition

{

num[counter++] = generateRandomNumber(); //using array to hold random function value.  

}

System.out.println("The array:"); //message

for(x = 0; x < 112; x++) // loop to count the value

{

if(x != 0 && x % 9 == 0) // if block to chek value

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// sort in ascending order

Arrays.sort(num); //using sort method

System.out.print("\n\nThe array in sorted order:"); // print value

for( x = 0; x < num.length; x++) // loop uses if block to check value is divisiable by 9  

{

if(x % 9 == 0) //check condition  

System.out.println(); // print  

else

System.out.print(num[x] + " "); // print array

}

// search for a number

System.out.print("\n\nEnter a number to search: "); // print message

find= ox.nextInt(); // input number by user

for(x= 0;x< num.length;x++) //loop to count values

{

if(num[x] == find) //check value

{

find_in = true; //change value

in= x;

break; //using break keyword

}

}

if(find_in)  //find value

System.out.println(find + " is found at index " + in); // print location

else

System.out.println("Not found"); //message

// display count of each numbers

System.out.println("Count of each numbers:"); //message

for(y = 1; y< num.length; y++) // loop to store element in counts array  

{

tem = num[y]; //hold value

counts[tem]++; //increment value

}

for(x = 1; x< counts.length; x++) //loop to print value

{

System.out.println(x + ": " + counts[x]); // print value

}

// average of the numbers in the array

for(x = 0; x < num.length; x++) // loop to calculate sum and average

{

sum += num[x]; //calculate sum

}

avg = (sum / 100); // calculate avg

System.out.println("\nThe average of the numbers in the array: " + avg);

// highest number in the array

int high= num[0]; //find number

for(x= 0;x < num.length;x++)

{

if(num[x] > high)

high = num[x]; //hold value of highest Number

}

System.out.println("\nThe highest number is: " + high); //print value

int low = num[0]; // defining variable for lowest number

for(x= 0; x < num.length - 1; x++) // loop to calculate lowest number

{

if(num[x] < low) //condition for lowest number

low = num[x]; //hold lowest number

}

System.out.println("\nThe lowest number is: " + low); //print value

}

public static int generateRandomNumber() //defining function  

{

Random ra = new Random(); //creating Random function Object

return (ra.nextInt(100)+ 1); //input and return value

}

}

Output:

the output of the given code is display in image

Explanation:

In the above program, an array is declared that uses a random function to input the number, in the next step the sort function is used, that sorted all array elements, in the next step the scanner class is used, that input the number form the user ends and pass search in the sorted array.

  • After searching the average of array elements is calculated. In this array we calculate the highest and lowest number of the array to print all the values the print method is used.
  • At the last, the rand method is used that generates the random number for the array and passes into a num array that prints the values.

7 0
3 years ago
a uniform density sheet of metal is cut into a shape of an isosceles triangle, which is oriented with the base at the bottom and
Cloud [144]

The horizontal center of mass will be located at the horizontal center of mass will be located on the center line. This is further explained below.

<h3>What is Location?</h3>

Generally, a location or place that is inhabited, open for occupation or distinguished by some distinctive feature: situation The setting of the property contributes significantly to its overall allure.

In conclusion, The center line will serve as the location for the horizontal center of mass, which will be found at the same location as the center line.

Read more about Location

brainly.com/question/11718756

#SPJ1

6 0
2 years ago
Write a program that uses the Purchase class in 5.13. Set the prices to the following: Oranges: 10 for $2.99 Eggs: 12 for $1.69
Xelga [282]

Answer:

Explanation:

The following program is written in Java. Using the program code from Purchase class in 5.13 I created each one of the fruit objects. Then I set the price for each object using the setPrice method. Then I set the number of each fruit that I intended on buying with the setNumberBought method. Finally, I called each objects getTotalCost method to get the final price of each object which was all added to the totalCost instance variable. This instance variable was printed as the total cost of the bill at the end of the program. My code HIGHLIGHTED BELOW

//Entire code is in text file attached below.

//MY CODE HERE

       DecimalFormat df = new DecimalFormat("0.00");

       oranges.setPrice(10, 2.99);

       oranges.setNumberBought(2*12);

       eggs.setPrice(12, 1.69);

       eggs.setNumberBought(2*12);

       apples.setPrice(3, 1);

       apples.setNumberBought(20);

       watermelons.setPrice(1, 4.39);

       watermelons.setNumberBought(2);

       bagels.setPrice(6, 3.50);

       bagels.setNumberBought(12);

       totalCost = oranges.getTotalCost() + eggs.getTotalCost() + apples.getTotalCost() + watermelons.getTotalCost() + bagels.getTotalCost();

       System.out.println("Total Cost: $" + df.format(totalCost));

   }

}

5 0
2 years ago
Instructions Write a program that allows the user to enter the last names of five candidates in a local election and the number
KengaRu [80]

Here is code in java.

import java.util.*;

class Election

{ //main method

   public static void main(String args[]){

      // create an object of Scanner class to read input

      Scanner s = new Scanner(System.in);

      // string array to store name of candidates

       String name[] = new String[5];

       // int array to store vote count of candidates

       int v_count[] = new int[5];

       double p = 0;

       int i = 0, sum = 0, high =0, win = 0;

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

       {

          System.out.print("last name of Candidate " + (i+1) + ":");

          // read name of Candidate

          name[i] = s.next();

          System.out.print(" number of votes received: ");

          // read vote of Candidate

           v_count[i] =s.nextInt();

if(v_count[i] > high)

              {

                  // highest vote

                  high = v_count[i];

                  win = i;

              }

              // total vote count

           sum +=v_count[i];

       }

     // printing the output

      System.out.println("\nCandidate\tVotes Received\t% of TotalVotes\n");

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

       {

           // % of vote of each Candidate

           p =(v_count[i]*100)/sum;

           // print the output

          System.out.println(name[i] + "\t\t" + v_count[i] + "\t\t\t" +p);

       }

       // print the total votes

      System.out.println("\nTotal Votes:\t" + sum);

      // print the Winner of the Election

       System.out.println("Winner of the Election is: " + name[win]);

   }

}

Explanation:

Create a string array "name" to store the name of candidates.Create Integer array "v_count" to store votes os each candidates.Calculate total votes of all candidates and find the highest vote amongst all candidate and print it.Find % of votes received by each candidate.Print these stats.

Output:

last name of Candidate 1:patel

number of votes received: 54

last name of Candidate 2:singh

number of votes received: 76

last name of Candidate 3:roy

number of votes received: 33

last name of Candidate 4:yadav

number of votes received: 98

last name of Candidate 5:sharma

number of votes received: 50

Candidate       Votes Received  % of TotalVotes

patel           54                      17.0

singh           76                      24.0

roy             33                      10.0

yadav           98                      31.0

sharma          50                      16.0

Total Votes:  311

Winner of the Election is: yadav

8 0
2 years ago
This unit is used to print the picture on a paper
NeTakaya

Answer:a printer

Explanation:

It prints things

7 0
2 years ago
Other questions:
  • Raeball was a lovin doll. And she spoke her mind as she stood tall. She made you special and loved. You're missed by so many. An
    10·2 answers
  • Why is it important to be a good digital citizen??
    11·1 answer
  • Fatal error: Class 'Drush\Commands\DrushCommands' not found in /Users/amy/testsite/Sites/acquia dev desktop/fresh-install/module
    7·1 answer
  • ________ is a remote access client/server protocol that provides authentication and authorization capabilities to users who are
    10·1 answer
  • In batch operating system three job J1 J2 and J3 are submitted for execution each job involes an I/O activity a CPU time and ano
    13·1 answer
  • Rolulzoss<br>A. State three positive uses of computers in the government sector​
    10·1 answer
  • is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
    10·1 answer
  • Quick!! Im taking a timed test so pls hurry!! Ill even mark as brainliets!!
    5·2 answers
  • Terence creates software requirements specification (SRS) documents for various software development projects. In which phase of
    6·1 answer
  • Jade has to create a workbook for storing information of students participating in the annual state-level sports competition. Th
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!