Compute the multiplication and comparison of them

Assignment Help Basic Computer Science
Reference no: EM13854473

Problem 1. This program will be graded based on whether the required functionality were implemented correctly instead of whether it produces the correct output, for the functionality part (80% of the grade).

Modify selection_sort.c so that it includes the following functions:

void selection_sort(int *a, int n);

int *find_largest(int *a, int n);

void swap(int *p, int *q);

selection_sort function: it should call find_largest function and swap function.

find_largest function: when passed an array of length n, the function will return a pointer to the array's largest element. The function should use pointer arithmetic - not subscripting - to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.

swap function: when passed the addresses of two variables, the function should exchange the values of the variables:

swap(&i, &j); /* exchange values of i and j */

Your program will call find_largest function and swap function in selection_sort function.

Problem 2.

A vector is an ordered collection of values in mathematics. An array is a very straightforward way to implement a vector on a computer. Two vectors are multiplied on an entry-by-entry basis, e.g. (1, 2, 3) * (4, 5, 6) = (4, 10, 18).

Write a program that include the following functions. The functions should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the functions.

void multi_vec (int *v1, int *v2, int *v3, int n);

int comp_vec(int *v1, int *v2, int n);

The multi_vec function multiplies vectors v1 and v2 and stores the result in v3. n is the length of the vectors.

The comp_vec function compares v1 and v2, return 1 if vectors v1 and v2 are equal (their corresponding components are equal), and 0 otherwise. n is the length of the vectors.

In the main function, ask the user to enter the length of the vectors, declare two arrays with the length, read in the values for two vectors, and call the two functions to compute the multiplication and comparison of them. The main function should display the result.

Enter the length of the vectors: 5

Enter the first vector: 3 4 9 1 4

Enter the second vector: 5 7 2 6 8

Output:

The multiplication of the vectors is: 15 28 18 6 32

The vectors are not the same.

Reference no: EM13854473

Questions Cloud

Gender and culture paper : Students will complete a 5 page paper (double spaced, 12pt., Times New Roman) paper on how sex and/or gender operate in a specific culture or subculture. Any culture is acceptable as long as conducting the research does not pose harm to you or anyone..
Discuss the classification of functionalities used : Discuss the classification of functionalities used in this article and leading vendors. Why are these classifications used and what do they mean
Briefly state how the cultures of both civilzations : Why did both the Mesopotamian and Egyptian civilzations emerge where they did, and what do you think were the biggest contributions of these two civilizations by 600 B.C.E. Briefly state how the cultures of both civilzations were preserved and spr..
What are risks associated with nikes core marketing strategy : What are the pros, cons, and risks associated with Nike"s core marketing strategy?
Compute the multiplication and comparison of them : Compute the multiplication and comparison of them. The main function should display the result.
A journalist was interested in college students : A journalist was interested in college students' knowledge of current events. The journalist compared a large group of college students to the general public using a questionnaire about recent items in the news. In this study, she tested large number..
Describe in detail a bad decision : Describe in detail a bad decision that you made at work in the past, or any work-related decision that you wish you could "do over." Be sure to indicate your career field, as you describe this decision. Analyze that bad decision using Steps 1-7 of th..
Financial statements and the closing process : The information needed to prepare the income statement is found in the Income Statement columns of the work sheet. Revenue is shown first, followed by an itemized and totaled list of expenses. Net income may be calculated or copied from the Income..
Design a raptor program that uses an array : Design a Raptor program that uses an array to store 5 values entered by the user and then displays the numbers in reverse order. Use two loops: one for reading the user entered values into the array

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Complement in tcp and udp connections

UDP and TCP use the 1s complement for their check sums. Suppose you have the following three 8-bit bytes: 10011001, 01010010, and 01011001.

  How to deal with each type of known attack

Include Denial of Service attacks, Spoofing, Replays, TCP Session Hijacking, and Attacks on Encrypted Data (such as passwords).

  How many days they worked and the total pay

Must have a input box to ask the user how many days they worked and the total pay must be in the form of currency.

  Computers on the internet have an assigned address

Computers on the Internet have an assigned address (location) called its Uniform Resource Locator (URL). The URL is used to identify one computer to the other computers on the Internet.

  How e-commerce is different from traditional retailing

Explain how e-commerce is different from traditional retailing? Write down some distinguishing features of digital markets and digital goods?

  Determine number of toes of chicken using calculations

If radix r utilized by chicken corresponds to its total number of toes, determine how many toes does chicken have on each foot?

  Identify scholarly work

In this assignment, you will research and identify scholarly work that you can use to support your research.

  What are online communities

What are online communities. How do online communities differ from traditional communities

  Select three imaging tools and explain their functions

Choose three imaging tools and describe their functions, including those of their subtools. Provide examples of how these tools might be used to enhance your professional or personal photos.

  Support desktop computers in small company

Static IP address of server is 192.168.45.200. Employees will open their Web browser and enter personnel.mycompany.com in URL address box to browse Web site.

  The disadvantages of allowing unlimited access

Employers can use a number of products to monitor their employees' use of the Internet. These products report an employee's access of non-business related Web sites. Advocates insist that these products conserve network resources, make workers mor..

  Is it ethical for a potential employer to use the internet

Digital Footprint , is it ethical for a potential employer to use the internet this way? Also is it legal?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd