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
irina [24]
3 years ago
9

Array Challenge Have the function ArrayChallenge (arr) take the array of numbers stored in arr and return the string true if any

two numbers can be multiplied so that the answer is greater than double the sum of all the elements in the array. If not, return the string false. For example: if arr is (2, 5, 6, -6, 16, 2, 3, 6, 5, 3] then the sum of all these elements is 42 and doubling it is 84. There are two elements in the array, 16 * 6 = 96 and 96 is greater than 84, so your program should return the string true. Examples Input: [2, 2, 2, 2, 4, 11 Output: false Input: 11, 1.2, 10, , 1, 121 Outputt true
Computers and Technology
1 answer:
vampirchik [111]3 years ago
6 0

Answer:

The code is given as follows,

Explanation:

Code:

#include <stdio.h>

#include <string.h>  

int n; //to store size of array  

char* ArrayChallenge(int arr[]) //function returns string true or false

{

  int i, j;

  int sum = 0;

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

  {

      sum = sum + arr[i]; //count sum

  }  

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

  {

      for(j = i+1; j < n; j++) //loop for every two elements in array

      {

          if(arr[i]*arr[j] > 2*sum) //check if proudct of two elements > 2 times sum

          {

              printf("\n%d x %d = %d, 2xSum = %d\n", arr[i], arr[j], arr[i]*arr[j], 2*sum);

              return "true"; //If proudct of two elements > 2 times sum. return true

          }

      }

  }

  return "false"; // If proudct of two elements < 2 times sum. return false

}  

int main()

{  

  printf("\nEnter size of array: ");

  scanf("%d", &n); //read size of array

  int A[n]; //array of size n

  printf("\nEnter array elements: ");

  int i;

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

  {

      scanf("%d", &A[i]); //read array from stdin

  }

  printf("%s\n",ArrayChallenge(A)); //ccall function and print answer

 

  return 0;

}

You might be interested in
Write a partial class that shows a class constant and an instance method. Write an instance method that converts feet to inches
MA_775_DIABLO [31]

Answer:

Please the code snippet below, the code was writen in Kotlin Language

Explanation:

const val inches:Int= 12 .   //This is the const value

fun main(args: Array<String>) {

 //this will ask the user for input

   print("Enter a number")            

  //this will do the conversion

var valueInFeet= Integer.valueOf(readLine())*inches

   print("The value in feet is $valueInFeet feet(s)")  

   }

4 0
2 years ago
In a paragraph of no less than 125 words, explain what netiquette is and how it improves efficiency and productivity in the work
Pani-rosa [81]

Netiquette actually means "Internet etiquette." Just like etiquette is a code of polite behavior in society, netiquette is a code of good behavior on the Internet. This includes several aspects of the Internet, such as email, sending memos, or basic communication regarding office task.

Now we should note that communication is not just a pivotal part of any organization, it is an integral part of any organization, without communication, an organization will suffer greatly. Communication is said to be effective when the receiver understands the message conveyed just as the sender wanted to,  having said that Netiquette improves efficiency and productivity in the workplace because it creates an avenue for efficient communication which includes clear instructions, fast message delivery, and proper explanation, and this bridges the gap between managers and employees even when they are miles apart. A clear message about a task makes it easier to carry out the said task, thereby resulting in high productivity in the workplace.

7 0
3 years ago
The Sleeping-Barber Problem:
s2008m [1.1K]

Answer:

Explanation:

Following are the Semaphores:

Customers: Counts waiting customers;

Barbers: Number of idle barbers (0 or 1)

mutex: Used for mutual exclusion.

Cutting: Ensures that the barber won’t cut another customer’s hair before the previous customer leaves

Shared data variable:

count_cust: Counts waiting customers. ------------copy of customers. As value of semaphores can’t access directly.

// shared data

semaphore customers = 0; semaphore barbers = 0; semaphore cutting = 0; semaphore mutex = 1;

int count_cust= 0;

void barber() {

while(true) { //shop is always open

wait(customers); //sleep when there are no waiting customers

wait(mutex); //mutex for accessing customers1

count_cust= count_cust-1; //customer left

signal(barbers);

signal(mutex);

cut_hair();

}

}

void customer() {

wait(mutex); //mutex for accessing count_cust

if (count_cust< n) {

count_cust= count_cust+1; //new customer

signal(customers); signal(mutex);

wait(barbers); //wait for available barbers get_haircut();

}

else { //do nothing (leave) when all chairs are used. signal(mutex);

}

}

cut_hair(){ waiting(cutting);

}

get_haircut(){

get hair cut for some time; signal(cutting);

}

6 0
3 years ago
Code a program that gets all possible solutions of a string using 3 for loops. Actual question attached
Nikitich [7]

\tt x=int(input("Enter\:first\:no:"))

\tt y=int(input("Enter\:second\:no:"))

\tt z=int(input("Enter\:third\:no:"))

\tt for\:x\:in\: range (3):

\quad\tt for\:y\:in\:range(3):

\quad\quad\tt for\:z\:in\:range(3):

\quad\quad\quad\tt if\:x!=y\:and\:y!=z\:and\:z!=x:

\quad\quad\quad\quad\tt print(x,y,z)

8 0
2 years ago
Suppose Pentax develops a new photo editing software and negotiates agreements with a Vietnamese manufacturer to assemble most P
Elis [28]

Answer:

Contract manufacturing

Explanation:

Contract manufacturing involves outsourcing a portion of a manufacturing process of a product to another company.

5 0
3 years ago
Other questions:
  • How can you prevent cyber bullying?
    13·2 answers
  • Describe network in terms of the class computer lab
    9·1 answer
  • In Broadbent's filter model of attention, the stages of information processing occur in which order?
    9·1 answer
  • The best way to safeguard your document is to save it
    11·1 answer
  • After Alexandra installed new software, she set it up to perform in a certain way. She is _____. changing the peripherals linkin
    10·1 answer
  • What Microsoft feature enables you to represent text as colorful visuals
    12·1 answer
  • Please answer this now I need please.
    5·1 answer
  • Which directory stores the cron configuration file?.
    8·1 answer
  • Colours can be contrasting if<br>​
    9·1 answer
  • For a certain company, the cost function for producing x items is C(x)=50x+100 and the revenue function for selling x items is R
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!