Pe 10-12
Pe 10-12
Work with your own group. Having identical programs is considered cheating.
Each program should be saved in a file with .c or .cpp extension and with name,
Lastname1_Lastname2_Lastname3_PE#
replace:
Email before the laboratory period ends (before 4pm). Late submissions will not
be accepted.
Global declarations are not allowed except for constants, prototypes, and structure
definitions.
#10: Dynamic Allocation. Write a program that dynamically allocates memory to an array
of n numbers.
o
The program should ask the user for n numbers and store these numbers to the
array.
The program should print the array and the sum of the numbers.
#11: Simple Structure. Write a program that defines a structure with four members (one
string, one integer, one double, one character) and has one instance. The members of
the structure must be given values by asking these from the user. The program must
print the values.
The program must implement a structure that contains structures (represents the
points) as members. This structure will represent the rectangle.
The program must ask the user for the coordinates of the two points.
Given the two points to form the diagonal, the program must compute for the
length of the diagonal.
The program must print the two points and the computed length of the diagonal.
Sample code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main () {
int a = -16;
int b;
double root;
b = abs(a);
printf (The absolute value of %d is %d, a, b);
root = sqrt(b);
printf (\nThe square root of %d is %.2lf, b, root);
getch();
return 0;
}
Note: For double values, you should use %lf as conversion specifier for printing. But, if the value
is still covered by the range for float, you can use %f.