Write a C function called values that returns void and takes two double precision arguments (called a and b) and one double precision array argument. The array argument has two rows and NDATA columns where NDATA is a symbolic constant. The function returns values using the array argument. On return from a function call, the first row of the array argument has NDATA values of x uniformly spaced between a and b inclusive and the second row has the corresponding values generated by the Bspline function of the previous exercise. Provide a main program to generate and print the array of values created by the function. Use NDATA set to 30, a=-2.5, b=3.0 (2) Write a C function called plot that takes the array generated in (1) as its first argument and produces a two dimensional character array with NR rows and NDATA columns where NDATA and NR are symbolic constants. This character array is the second argument of the function plot. This character array contains a plot of the data generated in (1) with all blanks in the array except where the function values are present and in these locations the character '*' is displayed. Arrange scaling so that the plot uses all rows of the display. The maximum y value(s) are displayed in row 0 of the character array. The main program prints this character array. (Note you will need to find maximum and minimum y values in the array of data to generate the proper scaling in the y direction). The '*' characters are placed at the nearest location as determined by conversion to an
integer (truncation, not rounding). Test with NDATA set to 30, NR set to 40, a=-2.5, b=3.0.
In addition to the above requirements, also satisfy the following:
1. Use only ONE C program for (1) and (2).
MY CODE
#include
#include
double
Bspline(double);
double
y=3.0;
double
x=-2.5;
int
main() {
printf(
"Giovanni Piniccilo\n");
for (x; x<=3.0; x= double (x+3.0/29.00)) {
Bspline(x);
printf(
"x= %10.6f y= %10.6f\n",x,y);
}
}
double
Bspline(double x){
if
(x >= -2&&x <-1){
return
(y= (1.0/4.0)*(x+2.0)*(x+2.0)*(x+ 2.0));
}
else
{
if
(x >= -1&&x <0){
return
(y=(1.0/4)+ (3.0/4)*(x+1)+(3/4)*(x+1)*(x+ 1)-(3/4)*(x+1)*(x+1)*(x+1));
}
else
{
if
(0 <= x&&x <1){
return
(y=(1.0/4)+ (3/4)*(1-x)+(3/4)*(1-x)*(1-x)- (3/4)*(1-x)*(1-x)*(1-x));
}
else
{
if
(1 <= x && x <2){
return
(y= (1.0/4)*(2-x)*(2-x)*(2-x));
}
else
{
return
(y=0.0);
}}}}
return
(0);
}
//Array
#define
size 30
int
sum(int x [][size];
int
main(){
int y[2][size]={{1,2,3,4},{5,6,7,8},{9,10,11,12};
printf(
"sum=%d\n", sum (y));
return 0;
}
int sum (int x[][size]){
int i,j, sum=0
for(i=0;i<3;i++){
for(j=0; jsum += x[i][j];
}
}
return sum;
}