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

  An unusual occurrence on the arpanet

An unusual occurrence on the ARPANET

  Evaluate events that could delay the closing of a project

Identify events that could delay the closing of a project or phase. Evaluate which event you believe would cause the longest delay and explain why. Provide an example to justify your answer

  Write an assembly program in using your own simd extensions

For an 8-wide SIMD machine (i.e., 8 parallel SIMD functional units, write an assembly program in using your own SIMD extensions to MIPS to execute the loop. Compare the number of instructions executed on the SIMD machine to the MIMD machine.

  Develop a personal action plan as a brochure

Develop a personal action plan as a brochure, using one of the templates in Microsoft® Word®. Include the following topics in your survival guide, using what you learned in class and My Career Plan

  Network mask for equally sized subnets

A site with a netid of 126.5.0.0/16 uses 20 subnet routers. Suggest a suitable network mask for equally sized subnets, which allows for a degree of expansion in the future. Give an example of a host IP address at this site.

  Represent 99 and -99 in 2s complement format

what are the largest(positive) and smallest (negative) integers a word can represent - Represent 99 and -99 in 2's complement format.

  Write a program calculates and displays the pay to workers

Create 3 workers and initialize their member variables with any data you choose. Store the workers in a Linked List. Write a function that will traverse the list of workers calculating and displaying the amount of pay each worker has earned.

  Create the computer system needed to store information

create the computer system needed to store and organize the information they collect. Whodunit would like your company to design a system to help them categorize, sort, store, and otherwise manipulate the thousands of artifacts they collect using ..

  Identify a performance problem in a business activity

Identify or select a performance problem in a business activity that you believe could be resolved or substantially improved by the acquisition of IT services performed by a contractor selected in open competition as a result of an RFP

  Design a class named rectangle to represent a rectangle

Design a class named Rectangle to represent a rectangle. The class contains: ? Two double data fields named width and height that specify the width and height of the rectangle.

  Convert from decimal to octal and hexadecimal

Convert from decimal to octal and hexadecimal a. 16.4 b. 39 c. 48.67

  Show how the value ascii miriam is stored in memory

Show how the value ASCII "MIRIAM" is stored in memory in Big Endian format starting at location 100 hexadecimal. Assume that each memory location stored two ASCII characters.

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