Reputation: 19
Task: Calculate the 25 values of the function y = ax'2 + bx + c on the interval [e, f], save them in the array Y and find the minimum and maximum values in this array.
#include <stdio.h>
#include <math.h>
int main()
{
float Y[25];
int i;
int x=3,a,b,c;
double y = a*pow(x,2)+b*x+c;
printf("a = ", b);
scanf("%d", &a);
printf("b = ", a);
scanf("%d", &b);
printf("c = ", c);
scanf("%d", &c);
for(i=0;i<25;i++)
{
printf("%f",y); //output results, not needed
x++;
}
system("pause");
}
Problems:
Upvotes: 0
Views: 256
Reputation: 96
#include<stdio.h>
#include<math.h>
int main()
{
double y[25];
double x,a,b,c,e,f;
int i,j=0;
printf("Enter a:",&a);
scanf("%lf",&a);
printf("Enter b:",&b);
scanf("%lf",&b);
printf("Enter c:",&c);
scanf("%lf",&c);
printf("Starting Range:",&e);
scanf("%lf",&e);
printf("Ending Range:",&f);
scanf("%lf",&f);
for(i=e;i<=f;i++)
{
y[j++]=(a*pow(i,2))+(b*i)+c;
}
printf("\nThe Maximum element in the given interval is %lf",y[j-1]);
printf("\nThe Minimum element in the given interval is %lf",y[0]);
}
Good LUCK!
Upvotes: 0
Reputation: 109
Problems:
(f-e) / 25(interval steps)
You need to use some form of loop to traverse the array and save the result of your calculation at every interval step. Something like this:
for(int i = 0; i < SIZE; i++)
// SIZE in this case 25, so you traverse from 0-24 since arrays start 0
For both cases:
traverse the array with some form of loop and check every item e.g. (again) something like this: for(int i = 0; i < SIZE; i++)
For min:
key = array[i]
;For max:
key = array[i]
;Finally, dont know what exactly i need to do to solve task
a*x^2 + b*x + c
n times for every step of your interval.Thats pretty much it. I will refrain from posting code(for now), since this looks like an assignment to me and I am confident that you can write the code with the information @Paul Ogilvie & I have provided yourself. Good Luck
Upvotes: 0
Reputation: 25286
You must first ask the user for the values of a, b, c
or initialize those variables, and ask for the interval values of e, f
, or initialize those variables.
Now you must calculate double interval= (f - e)/25.0
so you have the interval.
Then you must have a loop for (int i=0, double x=e; i<25; i++, x += interval)
and calculate each value of the function. You can choose to store the result in an array (declare one at the top) or print them directly.
Upvotes: 1