Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An m x n matrix is considered sparse if at most 20% of its elements are non-zero. A matrix MM is declared as int MM[200](200].

image text in transcribed

An m x n matrix is considered sparse if at most 20% of its elements are non-zero. A matrix MM is declared as int MM[200](200]. Write programming code to read, from file input.txt, values for m and n, followed by mn integers to fill the matrix in row order. Assume m, n 200. Your code then calls the function isSparse (see next) and prints a message indicating whether or not the matrix is sparse. Include all relevant I. (a) declarations Write a function isSparse which, given a matrix like MM and values for m and n returns 1 if the matrix is sparse and 0, otherwise. f a list of numbers is the number which appears most frequently. For de of 3 7 8 3 7 5 3 2 3 9 8 6 is 3 since it appears the most times example, the mo (4). A file mode. in contains numbers from 1 to 9 only. Each number can appear any number of times. There is no end-of-data marker but you can use the return value of fscanf to test when there is no more data. Write a program to read the data and print the number of times each number appears. Also, determine and print the mode of the numbers. Ignore the possibility of a tie Send all output to the file, mode.out. 16] (c) The pri me numbers from 1 to 400 can be obtained as follows. From a list of the numbers 1 to 400, cross out all multiples of 2 (but not 2 itself). Then, find the next number (i, say) that is not crossed out and cross out all multiples of t (but not including i). Repeat this last step provided that i has not exceeded 20 (the square root of 400). The numbers remaining in the list (except 1) are prime. Write a program which uses this method to prompt for a value for n (n 999) and print all prime numbers from 1 to n, inclusive. The following is a sample run Find primes up to ? 30 Primes from 1 to 30: 2 3 57 11 13 17 19 23 29 An array A contains n integers that first increase in value and then decrease in value, for example, (n (d) 11) 17 24 31 39 44 9 53 29 2 18 13 9 It is unknown at which point the numbers start to decrease. Write efficient code to copy the numbers in A to another array B so that B is sorted in ascending order. Your code must take advantage of the way the numbers are arranged in A. Hint: perform a merge starting from both ends. [51 Total Marks Q1: 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions