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
nadya68 [22]
3 years ago
9

Write a C or C program A6p2.c(pp) that accepts one command line argument which is an integer n between 2 and 4 inclusive. Genera

te 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (i.e.,int a[5][12];). Use pthread to create n threads to square all 60 array elements in place. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as 5 by 12 matrices.

Computers and Technology
1 answer:
victus00 [196]3 years ago
6 0

Answer:

The code is as given below. The output is attached as the attachments

Explanation:

#include <iostream>

#include <cstdlib>

#include <pthread.h>

using namespace std;

#define c 12 // defining number of columns

#define r 5 //defining number of rows

int chunk; //initializing variable chunk

int n=0; //defining variable n as 0

int arry[r][c] ; //initializing the array as 5x12

void Squared(void threadid) {

long td; //initializing the variable td

 

td = (long)threadid; //typecasting threader to long

 

int s = td * chunk; //defining variable s for the start

int e=s+chunk-1;//defining variable e for the end

for(int i=0; i<r; i++){ //initializing for loop for rows

for(int j=0;j<c;j++){ //initializing for loop for columns

int pos = i*c + j; //defining variable

if(pos>=s&&pos<=e)//condition to make sure the values in within the chunk range

{

arry[i][j]=arry[i][j]*arry[i][j]; //squaring the terms

}

}

}

pthread_exit(NULL);

}

int main () {

cin>>n; //taking number n from 2 to 4 inclusive from the user

pthread_t threads[n];

int rc; //initializing variable rc for threads

int i,j,k; //initializing variables i,j,k

//filling array with data

for(i=0;i<r;i++) //for loop for rows

{

for(j=0;j<c;j++)  //for loop for columns

{

arry[i][j]=(rand() % 49) + 1;  //Creating random integers

}

}

//Printing Random Array

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

{

cout<<"\n";

for(j=0;j<c;j++)

{

cout<<arry[i][j]<<"\t";

}

}

chunk = (60 + n - 1) / n; // divide by threads rounded up.

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

cout << "\n main() : creating thread, " << i << endl;

rc = pthread_create(&threads[i], NULL, Squared, (void *)i); //creating the threads

if (rc) {

cout << "Error:unable to create thread," << rc << endl;

exit(-1);

}

}

//Printing Result Array

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

{

cout<<"\n";

for(j=0;j<c;j++)

{

cout<<arry[i][j]<<"\t";

}

}

pthread_exit(NULL);

}

You might be interested in
Write the definition of a function named printpoweroftwostars that receives a non-negative integer n and prints a line consistin
Aleksandr-060686 [28]
To accomplish this without using a loop,
we can use math on a string.

Example:
print("apple" * 8)

Output:
appleappleappleappleappleappleappleapple

In this example,
the multiplication by 8 actually creates 8 copies of the string.

So that's the type of logic we want to apply to our problem.

<span>def powersOfTwo(number):
if number >= 0:
return print("*" * 2**number)
else:
<span>return

Hmm I can't make indentations in this box,
so it's doesn't format correctly.
Hopefully you get the idea though.

We're taking the string containing an asterisk and copying it 2^(number) times.

Beyond that you will need to call the function below.
Test it with some different values.

powersOfTwo(4) should print 2^4 asterisks: ****************</span></span>
4 0
4 years ago
Help with scripting/coding questions!
user100 [1]

Answer:

Explanation:

For the first questions the variable's name is <u>Today,</u> and is declared like a date variable, this will be returned a date value.

For the second question, where the browser will show today's date because with the variable Today, we get the date and with the document.write(Today) is shown the variable information.

With the third question, the result will be "Hello!", because the August is the 8 month, and July the 7, in this case the IF is False and for that will show "Hello!".

5 0
3 years ago
A Turing machine with stay put instead of left is similar to an ordinary Turing machine, but the transition function has the for
sasho [114]

Answer:

The class of language the machines recognise is Regular Language (See Explanation Below)

Explanation:

Given

Form δ : Q × Γ → Q × Γ × {R, S}

From the above transition form, it can be seen that the machine cannot read square symbols passed to it.

Regarding the square the machine is currently reading, there are multiple movement of S and it shouldn't be so because any number of the multiple movement can be simulated by exactly one movement of S.

As stated earlier that sequence of moves can be simulated by just one movement.

Let R = the movement

This means the machine can only use right move efficiently.

With this, we can say that the machine only read input string.

This is a characteristic of DFA (Deterministic Finite Automata).

With this, we can conclude that some DFAs will simulate the Turing machine and that they only read regular language.

5 0
3 years ago
What kind of internal factors influence the process of business enterprise
fgiga [73]

Answer:

The three main internal factors are:

Human resources

Finance

Current or modern technology

Explanation:

Financial resources like funding, investment opportunities, and sources of income.

Physical resources like the company's location, equipment, and facilities.

Human resources like employees, target audiences, and volunteers.

4 0
2 years ago
Windows server 2012 supports two types of folder shares. what are those two types?
nadya68 [22]
Network File System and Server Message Blocks
4 0
3 years ago
Other questions:
  • A person who enjoyed making paper airplanes as a child might very well find a satisfying career as a(n) _____ engineer.
    7·2 answers
  • Where does most of the work in creating a presentation will take place? Either formatting toolbar, normal (Slide) view, slide so
    12·2 answers
  • Convert the Binary Number to a Decimal Number
    13·1 answer
  • A customer has a system with a Gigabyte B450 Aorus Pro motherboard. He wants to upgrade the processor from the AMD Athlon X4 950
    8·2 answers
  • What is meant by polling mode in communication between software andUART and what is its disadvantage as compared to interrupt mo
    14·1 answer
  • Which CSS attribute would change an element's font color to blue
    15·2 answers
  • An employee clicks on a link in an email from what looks like a fellow employee and is taken to a fraudulent web site which asks
    6·2 answers
  • As u type where does excel display the entry
    10·1 answer
  • list out the application of the computer and explain it?(and as the answer for this question as image) ​
    7·1 answer
  • PLEASE HELP I WILL GIVE BRAINLIEST!!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!