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
Anna [14]
3 years ago
6

Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in

t to represent the day.
Computers and Technology
1 answer:
frozen [14]3 years ago
8 0

Answer:

void season(char * month, int day){

if(strcpy(month, "January") == 0 || strcpy(month, "February") == 0)

printf("Winter\n");

else if(strcpy(month, "March") == 0){

if(day < 20)

printf("Winter\n");

else

printf("Spring\n");

}

else if(strcpy(month, "April") == 0 || strcpy(month, "May") == 0)

printf("Spring\n");

else if(strcpy(month, "June") == 0){

if(day < 20)

printf("Spring\n");

else

printf("Summer\n");

}

else if(strcpy(month, "July") == 0 || strcpy(month, "August") == 0)

printf("Summer\n");

else if(strcpy(month, "September") == 0){

if(day < 20)

printf("Summer\n");

else

printf("Autumn\n");

}

else if(strcpy(month, "October") == 0 || strcpy(month, "November") == 0)

printf("Autumn\n");

else if(strcpy(month, "December") == 0){

if(day < 20)

printf("Autumn\n");

else

printf("Winter\n");

}

}

Explanation:

I am going to write a C program for this.

I am going to use the function strcpy, from the library string.h, to compare strings. It returns 0 when strings are equal.

I am going to say that the season change happens at day 20, in March, June, September and December

void season(char * month, int day){

if(strcpy(month, "January") == 0 || strcpy(month, "February") == 0)

printf("Winter\n");

else if(strcpy(month, "March") == 0){

if(day < 20)

printf("Winter\n");

else

printf("Spring\n");

}

else if(strcpy(month, "April") == 0 || strcpy(month, "May") == 0)

printf("Spring\n");

else if(strcpy(month, "June") == 0){

if(day < 20)

printf("Spring\n");

else

printf("Summer\n");

}

else if(strcpy(month, "July") == 0 || strcpy(month, "August") == 0)

printf("Summer\n");

else if(strcpy(month, "September") == 0){

if(day < 20)

printf("Summer\n");

else

printf("Autumn\n");

}

else if(strcpy(month, "October") == 0 || strcpy(month, "November") == 0)

printf("Autumn\n");

else if(strcpy(month, "December") == 0){

if(day < 20)

printf("Autumn\n");

else

printf("Winter\n");

}

}

You might be interested in
(ANSWER!)
andreev551 [17]

Answer:

it doesn't? maybe it helps by resetting it but other than that I don't think It does anything

4 0
3 years ago
Read 2 more answers
Write a C program that creates two threads to run the Fibonacci and the Runner processes. Threads will indicate the start and th
OleMash [197]

Answer:

see explaination

Explanation:

#include <pthread.h>

#include <stdio.h>

int sumOfN = 0;

int arr[1000];

int n;

void * findSumOfN(void *a){

printf("Thread 1 Starting\n");

sumOfN = (n * (n+1)) / 2; //finds sum of first n natural numbers

printf("Thread 1 Finished\n");

pthread_exit(0);

}

void * fibonacci(void *a){

printf("Thread 2 Starting\n");

arr[0]=0;

arr[1]=1;

for(int i=2;i<n;i++) //find fibonacci numbers iteratively

arr[i]=arr[i-1]+arr[i-2];

printf("Thread 2 Finished\n");

pthread_exit(0);

}

int main(void){

printf("Please enter the value of n \n");

scanf("%d", &n);

if (n <= 0)

{

printf("Wrong input ! \n"); //input validation

return 0;

}

pthread_t thread1, thread2;

pthread_create(&thread1,NULL, findSumOfN, NULL); //Create threads

pthread_create(&thread2,NULL, fibonacci, NULL);

pthread_join(thread1,NULL); //Start threads

pthread_join(thread2, NULL);

printf("The sum of first %d numbers is : %d \n",n, sumOfN);

printf("The first %d fibonacci numbers are : \n",n);

for (int i = 0; i < n; ++i)

{

printf("%d ", arr[i]);

}

printf("\n");

return(0);

}

3 0
3 years ago
What trade-offs do you think engineers make between functionality, safety and aesthetics when building a real bridge?
elena55 [62]
Deciding where it should go
6 0
3 years ago
You have an interface on a router with the ip address in the class c network subnet of 192.168.192.10/29. how many total host ad
Gemiola [76]
If 29 bits of the 32 available addressing bits are used for the subnet, then only 3 bits giving 2^3=8 combinations remain for the host addresses. 

In reality, the all zeros and all ones addresses are reserved. So, 8 addresses can exist, but 6 of those are available.

The way the question is formulated it seems the answer 8 is what they're after.
8 0
3 years ago
What are the major differences between searching and sorting in Java? What are some of the differences in the techniques used in
Studentka2010 [4]

Answer:  

  • Searching is a technique to look for an item or target value in a data structure like searching for a phone number in a directory.Data structure can be an array,List etc. Searching algorithms are used for searching. Most common examples are Linear Search and Binary Search. Lets take the example Linear Search in order to explain it using JAVA. Its the simplest searching algorithm. To search for a specific element, look at each element in the data structure sequentially and check if it matches with the element being searched for.
  • Sorting is a technique of arranging the elements in a specific order e.g. numerical sorting, ordering students according to their exam score. This order can be ascending or descending or alphabetical order. Contrary to search it returns the data structure e.g. an array in which the elements of array are sorted in a particular order. Sorting algorithms are used to sort elements in a data structure. Some common examples of sorting algorithms are Bubble Sort, Insertion Sort, Selection Sort, Merge Sort, Quick Sort, Heap Sort etc. JAVA uses Array.Sort() built-in function for sorting an array. By default it sorts the input array in ascending order.
  • Selection Sort: It is a sorting technique which divides an array into two subarrays. One subarray in the left is sorted and the other one at right is unsorted. This is an in-place algorithm. It is not a good option for large data. Initially the sorted part is empty and all elements are placed in unsorted array. First the element which is the smallest in the unsorted array is selected and swapped with the leftmost array element and becomes part of the sorted array. In each iteration the smallest element from the unsorted array is selected and moved to sorted part of the array.The worst case time complexity of this algorithm is O(n)^2 as we have to find the smallest for every element in the array.
  • Merge Sort: It is a comparison based algorithm. It works on divide and conquer technique. It uses recursion approach for sorting. This means it breaks the problem(lets say array list to be sorted) into sub problems (smaller parts) and then solves (in this case sorts) each sub problem in a recursive manner. At the end it merges the solutions (hence the merged sorted array). Although selection sort works faster when data set is small merge sort outperforms it for larger data sets. Merge sort is a stable algorithm and works best for linked lists. Its not an in place algorithm. Time complexity of merge sort is O(n*log n) for best, average and worst cases because it always divides the array in two parts and takes linear time to merge these part. O(n(logn)) time complexity makes it better,more efficient and faster to sort large data sets.
  •  Big Oh O notation is an asymptotic annotation written as O(n) which is a mathematical way to represent the upper bound of the running time of   algorithm (sorting algorithm in this case). It computes the worst case time complexity. Worst case time complexity means that the longest amount of time or maximum number of operations that will be required for a sorting algorithm to complete. The time complexity mostly gets affected as the size of the input varies.
  • For example lets find out the worst-case time complexity of Bubble Sort for a list of n elements. Worst case is when the array is reversed sorted. At first iteration it would make n-1 comparisons. At iteration 1, for n-2 times and so total comparison will be O(n^)2. So the time to run program is proportional to the square of the input size.
  • Searching algorithms are used when there is a need to find a specific data item from bulk of data item. Searching algorithms make this hectic process easier. For example you want to find phone number of person from directory. without searching algorithm looking for each phone number in the directory manually can be very time consuming. For example you have to find address of a customer number 254 from database to deliver a product. Instead  of manually looking for customer numbers you can simply use  linear search algorithm that will start from customer 1 and sequentially searches for specific customer 254 number and provides the address in a shorter time.
  • Sorting reduces complexity of problems e.g reducing the searching complexity. It is easier to locate data elements in a sorted list than unsorted. For example comparing two large data sets containing millions of records. If both the data sets are ordered, the comparison gets easier. Moreover every sorting algorithm has certain usage. Like merge sort is useful for linked lists,heap sort is good with arrays and uses less memory. If data is small with large values, selections sort is better for this. It doesn’t require any additional space. Databases use merge sort to arrange data that is too large to be loaded completely into memory.  Heap sort is used in reading bar codes on plastic cards. Quick sort is used to maintain sports score on the basis of win-loss ratio.
5 0
2 years ago
Other questions:
  • What is authentication?
    8·1 answer
  • Discuss Hashing and how it is utilized within the IT industry. Also, discuss how Hashing can improve our sorting and searching r
    12·1 answer
  • PLEASE HELP ASAP!!!!
    14·1 answer
  • WILL GIVE BRANLYIST
    6·1 answer
  • When using a wireless mouse, what is the most common port used for the transmitter? 
    7·1 answer
  • The file extensions .webm, .m4v, and .ogv are used for:
    15·1 answer
  • The ability of services to grow or shrink based on need is called __________.
    14·1 answer
  • Which of the following techniques would a Baroque composer most likely employ to evoke an affect of agitation? Select one:
    14·1 answer
  • The ______________ shows that you have fully researched the topic and gives you a chance to prove your claim.
    8·1 answer
  • When using the Photo Album dialog box, a picture
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!