Question

In: Computer Science

*** C language *** Make a  list of all of the different zip codes that the zombies...

*** C language ***

Make a  list of all of the different zip codes that the zombies live at and a count of how many
zombies live at that zip code. The list should be sorted based on the zip code with the
smallest zip code printed first. Example:
Zip Code # Zombies

31234 2

//variables

int zip[] = {37643,31234,32785,32643,32785,32643,31234,31234,32643,32643,31234,32785,32785,32643,31234};

char zombie[]={'N','Y','Y','N','Y','Y','Y','N','Y','Y','N','Y','Y','Y','Y'};

Y = zombie N = Not zombie

int zPatient = 0;
int nonZpatient = 0;
for(int pt = 0; pt < (*(&zombie + 1) - zombie); pt++)
{
if(zombie[pt] == 'N')
{
nonZpatient++;
}
else if (zombie[pt] == 'Y')
{
zPatient++;
}
}


Solutions

Expert Solution

Below is the code for the above problem.;


#include <stdio.h>

//main method to initialize the program
int main()
{
//array of zipcode
int zip[] = {37643,31234,32785,32643,32785,32643,31234,31234,32643,32643,31234,32785,32785,32643,31234};
//array of zombies status
char zombie[]={'N','Y','Y','N','Y','Y','Y','N','Y','Y','N','Y','Y','Y','Y'};
//to count no.of zombies
int zPatient = 0;
int nonXpatient = 0;
int zipcode;
printf("Enter the zipcode you want to search for zombies\n");
scanf("%d",&zipcode);
//traverse the zipcodes
for(int i = 0;i<(sizeof(zip)/sizeof(int));i++)
{
if(zip[i]==zipcode && zombie[i]=='Y') //if there is zombie
{
zPatient++;
}
if(zip[i]==zipcode && zombie[i]=='N') //if there is no zombie
{
zPatient++;
}
}
printf("zipcode : %d\n",zipcode);
printf("zombies : %d\n",zPatient);
return 0;
}

OUTPUT:


Related Solutions

6) How many different 5-digits zip codes can we have? A) 100,000 B) 90,000 C) 81,000...
6) How many different 5-digits zip codes can we have? A) 100,000 B) 90,000 C) 81,000 D) 80,000 7) How many different 5-digits zip codes can we have with no zero as the first digit? A) 100,000 B) 90,000 C) 81,000 D) 80,000 8) How many different 5-digits zip codes can we have with no zero as the first and last digit? A) 100,000 B) 90,000 C) 81,000 D) 80,000 9) A security code consists of 4 parts, two digits...
A zip code is a string of five digits (0,1,2,3,4,5,6,7,8,9). How many zip codes are there...
A zip code is a string of five digits (0,1,2,3,4,5,6,7,8,9). How many zip codes are there subject to the following restrictions? (1) Only even digits are allowed. (2) The first digital is even and the last digit is odd (3) Digits cannot be repeated (4) 0 appears exactly four times (5) 0 appears at at least once Solve the following discrete mathematics problem above. Show all work/explanations
You have colleagues who reside in different zip codes. Which measure(s) of central tendency or other...
You have colleagues who reside in different zip codes. Which measure(s) of central tendency or other descriptive statistics would you use to describe this information? (please answer in full paragraphs - thank you)
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing...
In C/C++ programming language, write down the lines of codes (and figure) to show- a) assignment-by-sharing b) dangling reference
Central Tendency & Descriptive Statistics: You have colleagues who reside in different zip codes. Which measure(s)...
Central Tendency & Descriptive Statistics: You have colleagues who reside in different zip codes. Which measure(s) of central tendency (mean, median, mode) or other descriptive statistics would you use to describe this information? (please answer in full paragraph - thank you)
The sales prices of homes (in dollars) from a random sample of 10 zip codes in...
The sales prices of homes (in dollars) from a random sample of 10 zip codes in the United States are recorded in the following table. At the 0.10 level of significance, is there evidence of a difference in the mean selling price for homes between 2001 and 2002? ii.Determine the p-value in (i) and interpret its meaning. Town 2001 2002 Alexandria 245795 293266 Boston 391750 408803 Decatur 205270 227561 Kirkland 326524 333569 New York 545363 531098 Philadelphia 185736 197874 Phoenix...
What is the best way to combined both of these codes to make it work all...
What is the best way to combined both of these codes to make it work all together? <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Login and Registeration Form Design</title> <link rel="stylesheet" type="text/css" href="signin.css"> <script> function myFunction(){ document.getElementById('demo').innerHTML = document.getElementById('fname').value + " " + document.getElementById('lname').value + " " + document.getElementById('street').value + " " + document.getElementById('city').value + " " + document.getElementById('zcode').value + " " + document.getElementById('email').value + " " + document.getElementById('phone').value; } </script> </head> <body> <div class="login-page"> <div class="form"> <br> <h1> Register </h1>...
C# What to submit: One zip file named Ass3.zip This zip must contain one VS 2017...
C# What to submit: One zip file named Ass3.zip This zip must contain one VS 2017 solution named Ass3, which contains one C# Windows Forms App project also named Ass3 and the project contains a default form, Form1.cs and Program.cs. No change should be made in Program.cs, but your Form1 must be designed and implemented to satisfy the following requirements. **Do not submit only a single file of the solution or project. The whole solution folder of VS 2017 must...
make a calculator in C++ or C language that can take up to 5 values at...
make a calculator in C++ or C language that can take up to 5 values at same time
Define the equivalence partitions and give suitable test cases for the following: Zip codes: Range from...
Define the equivalence partitions and give suitable test cases for the following: Zip codes: Range from 00600 to 98000 inclusive. States: AL (Alabama) to WY (Wyoming) Last Name: One through twelve characters (alphabetic, space and hyphen) User ID: Eight characters, at least two of which are not alphabetic (numeric, special characters) For full credit, you should give one test case for each equivalence partition defined by you, even if it is possible to cover more than one partitions in one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT