Answer the question
In order to leave comments, you need to log in
How to pass a structure declared locally to other functions?
I have a program for tabulating a function at some interval. The gap is set by the start, end and tab step. Eti parameters I express one structure. The program is executed in the style of procedural programming. and here is the question. How can I declare a structure locally and then pass it to other functions. Attached is the text of the program. it is executed without a structure, and the parameters are begin, end, step. Help and indicate what and where to fix for the desired result.
#include <stdio.h>
void Task1(void);
void GettingTabulationOptions(double *begin, double *max_x, double *step);
void TabulationAccordingToTheParameters(double begin, double end, double step);
double SquareValue(double x);
void main()
{
Task1();
}
void Task1(void)
{
double begin,end,step;
GettingTabulationOptions(&begin, &end, &step);
TabulationAccordingToTheParameters(begin, end, step);
}
void GettingTabulationOptions(double *begin, double *end, double *step)
{
printf("y=x^2\n");
printf("begin=");
scanf("%lf", &*(begin));
printf("end=");
scanf("%lf", &*(end));
printf("step=");
scanf("%lf", &*(step));
}
void TabulationAccordingToTheParameters(double begin, double end, double step)
{
double x,y;
for (x=begin; x<=end; x+=step)
{
y=SquareValue(x);
printf("x=%lf\t y=%lf\n", x, y);
}
}
double SquareValue(double x)
{
return x*x;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question