Name: NoKo 2009-06-06 0:30
Add
code for the 2 void functions at the bottom. Add additional functions
after each prob(), if needed. For example, if you are adding a function
for prob2(), write the function after prob2(). The
function prototypes, placed above main(), can be in any order. You do
not need to change anything in main.
matrix.dat:
-1.0 1.0 -4.0 -0.5
2.0 1.5 3.0 2.1
-3.1 0.7 -2.5 4.2
1.4 0.3 2.4 -1.9
0.0 1.2 -3.0 -0.5
The assigned problems are:
prob1(): By using the functions calloc() or malloc() allocate
the memory to store n integer values in int *v. Suppose n=8. Enter 8 integer
values randomly from the keyboard and save them in int v[]. Print the
components of the vector v[] on the screen.
Rearrange the components of v[] in descending order starting from
the largest number. Print the components of rearranged v[] on the screen.
.............................. ..............................
.................
Your output for Problem 1 should look like:
Enter a positive integer n: 8
Enter 8 integers: 6 1 -4 2 7 3 1 0
The vector is:
v[] = { 6 1 -4 2 7 3 1 0 }
The ordered vector is:
v[] = { 7 6 3 2 1 1 0 -4 }
................................................................................
prob2(): By using a pointer to pointers **A and **B and the function calloc()
allocate the memory for the 4x4 matrices A[][] and B[][].
By using the pointers *a and *b and the function malloc()
allocate the memory for the 4-dimensional vectors a[] and b[].
Read the components of A and a from the given input file matrix.dat
(which is in the public/final directory; you need to copy it into your directory
).
The last line of the input file contains the components of a. The rows of
matrix A are the first four lines of the input file. Print the components
of A[][] and a[]. By calling the function pmatrix(A,B,a,b,n), n=4,
which you will construct, determine the components of the matrix B=1.7*A*A, and
the
vector b=(A*a)-1.5*a. Print the components of the matrix B and the vector b in t
he main.
Free dinamically allocated memory.
..............................
..............................
....................
Your output for Problem 2 should look like:
Matrix A is:
-1.000 1.500 -2.000 -0.500
2.500 1.500 3.500 2.400
-3.000 0.800 -2.600 4.400
1.200 0.600 2.200 -1.700
Vector a is:
a[] = 1.500 1.700 -2.600 -0.800
Matrix B is:
...... ...... ...... ......
...... ...... ...... ......
...... ...... ...... ......
...... ...... ...... ......
Vector b is:
b[] = ..... ..... ..... .....
*/
#include <stdio.h>
#include <math.h>
/* function prototypes */
void prob1(void);
void prob2(void);
/* add here additional function prototypes as needed */
main()
{
int menu;
printf("Enter the function number to execute (1-2):");
scanf("%d", &menu);
switch(menu){
case 1:
prob1();
break;
case 2:
prob2();
break;
default:
printf("prob%d() does not exist.\n", menu);
}
exit(0);
}
void prob1(void)
{
/* Put your solution for problem 1 here: */
}
/* add the needed functions for prob1() */
void prob2(void)
{
/* Put your solution for problem 2 here: */
}
/* add the needed function for prob2() */
/*