Docsity

Assignment 11 for CGS3460 Fall 2007 - Complex Numbers and Matrix Operations, Assignments of Computer Science

Toggle sidebar
bg1
CGS3460 Fall 2007
Assignment 11
Assigned: 11/13, Tue
Due: 11/17, Sat
1. Write a program which implements the following function
void sub_sum(float *x1, float *i1, float *x2, float *i2)
This function receives two complex numbers (one in x1 and i1 and another in x2 and i2), returns
their sum in x1 and i1 and returns their difference in x2 and i2. Your program must obtain the
values for x1, x2, i1 and i2 from the user and these must be float.
A complex number is a number of the form a+ib where a and b are real numbers (e.g. 1.5 + 3.0i).
Sum and difference of complex numbers are defined component wise i.e. (a1+ib1) + (a2+ib2) =
(a1+a2) + i(b1+b2) and (a1+ib1) - (a2+ib2) = (a1-a2) + i(b1-b2). See
http://en.wikipedia.org/wiki/Complex_number for details. Save this program in a file called p1.c.
Example 1:
Enter first complex number: 20.22+i9
Enter first complex number: 2+i2
Sum:22.219999 + i11.000000
Difference:18.219999 + i7.000000
Example 2:
Enter first complex number: 2+i3
Enter first complex number: 23+i4
Sum:25.000000 + i7.000000
Difference:-21.000000 + i-1.000000
Example 3:
Enter first complex number: 0+i0
Enter first complex number: 0+i0
Sum:0.000000 + i0.000000
Difference:0.000000 + i0.000000
2. Write a program which implements the following function
void vec_to_mat(int *v, int *mat, int n);
Here v is an array with 9 elements, stored in the row major (matrix is converted to array row-
wise) representation. mat is an 3x3 matrix. The function should copy the elements from v to mat.
You must obtain the values in v from the user. Display the values in mat in a 3x3 grid once the
copying is done.
Save this program in a file called p2.c. You don’t have to handle the cases with invalid input. You
must read input from the terminal till the user enters a -1. -1 is not a part of the list.
Example 1:
Enter integers, ending with -1.
9 8 7 6 5 4 3 2 1 -1
9 8 7
6 5 4
3 2 1
pf2

Partial preview of the text

Download Assignment 11 for CGS3460 Fall 2007 - Complex Numbers and Matrix Operations and more Assignments Computer Science in PDF only on Docsity!

CGS3460 Fall 2007

Assignment 11

Assigned: 11/13, Tue Due: 11/17, Sat

  1. Write a program which implements the following function void sub_sum(float *x1, float *i1, float *x2, float *i2) This function receives two complex numbers (one in x1 and i1 and another in x2 and i2), returns their sum in x1 and i1 and returns their difference in x2 and i2. Your program must obtain the values for x1, x2, i1 and i2 from the user and these must be float.

A complex number is a number of the form a+ib where a and b are real numbers (e.g. 1.5 + 3.0i). Sum and difference of complex numbers are defined component wise i.e. (a1+ib1) + (a2+ib2) = (a1+a2) + i(b1+b2) and (a1+ib1) - (a2+ib2) = (a1-a2) + i(b1-b2). See http://en.wikipedia.org/wiki/Complex_number for details. Save this program in a file called p1.c.

Example 1: Enter first complex number: 20.22+i Enter first complex number: 2+i Sum:22.219999 + i11. Difference:18.219999 + i7.

Example 2: Enter first complex number: 2+i Enter first complex number: 23+i Sum:25.000000 + i7. Difference:-21.000000 + i-1.

Example 3: Enter first complex number: 0+i Enter first complex number: 0+i Sum:0.000000 + i0. Difference:0.000000 + i0.

  1. Write a program which implements the following function void vec_to_mat(int *v, int *mat, int n); Here v is an array with 9 elements, stored in the row major (matrix is converted to array row- wise) representation. mat is an 3x3 matrix. The function should copy the elements from v to mat. You must obtain the values in v from the user. Display the values in mat in a 3x3 grid once the copying is done.

Save this program in a file called p2.c. You don’t have to handle the cases with invalid input. You must read input from the terminal till the user enters a -1. -1 is not a part of the list.

Example 1: Enter integers, ending with -1. 9 8 7 6 5 4 3 2 1 - 9 8 7 6 5 4 3 2 1

Example 2: Enter integers, ending with -1. 1 2 3 4 5 6 7 8 9 - 1 2 3 4 5 6 7 8 9

  1. Write a program that obtains 10 integers from the user into an array and then sorts them (ascending order) without using array indexing i.e. at no point must you access an element from the array using a statement like arr[3]. Your implementation must use the array name pointer to access and sort various elements in the list. Array indexing must not be used even while obtaining input or displaying output. Save this program in a file called p3.c. You must read input from the terminal till the user enters a -1. -1 is not a part of the list. You can choose any algorithm you like for sorting.

Example 1: Enter integers, ending with -1. 5 4 3 2 1 - Array before sorting: 5 4 3 2 1 Array after sorting: 1 2 3 4 5

Example 2: Enter integers, ending with -1. 1 1 1 1 1 - Array before sorting: 1 1 1 1 1 Array after sorting: 1 1 1 1 1

Example 3: Enter integers, ending with -1. 12 - Array before sorting: 12 Array after sorting: 12

Instructions for submitting Assignment 11

  1. First compress your program files into a single file. At the terminal command prompt (Putty incase you are working from Windows) type tar cvf assign11.tar p1.c p2.c p3.c. This should create the compressed file assign11.tar
  2. If you are working from Windows platform using Putty and WinSCP, you can transfer the tar file back to your Windows machine using WinSCP. It is reverse of the process you probably used to transfer your program(s) from your local machine to CISE machine.
  3. Upload the assign11.tar to CourseWorX at the course webpage.