0
How can i find out a square,cube and square root of a number using pointers? In c language
6 odpowiedzi
+ 4
First, from now on, include the language tag to your post!
Second, from now on, provide your attempt along with the assignment!
Third, from now on, Try to use your creativity more!
How to post a minimal, complete, and verifiable question in SL's term.
" Here are some tips to make sure your question qualifies:
- Post only programming-related QUESTIONS and ANSWERS;
- SEARCH for similar QUESTIONS or ANSWERS before posting;
- Include relevant TAGS;
- Follow community RULES: https://www.sololearn.com/Content-Creation-Guidelines/
DO NOT
- Post spam/advertisement;
- Use inappropriate language.
* Post general discussions and open-ended questions in your feed.
** In case of an assignment, providing a code snippet is mandatory."
+ 3
You broke the TAGGING rule + didn't show us your best attempt, unfortunately!
+ 3
Good luck, my friend!
+ 2
In a classic fashion, you'd define a custom type to hold all operations results and a function to perform 3 aforementioned operations.
[NOTE: Also, you'd define 3 different functions to do the job without defining any custom data type.]
typedef struct {
int square;
int cube;
double squareRoot;
} aggregate_t ;
Then you construct a function like so
void doMath(aggregate_t *data, int number) {
data->square = number * number;
data->cube = number * number * number;
data->squareRoot = sqrt(number);
}
And finally, prepare the main function like this
int main()
{
aggregate_t *d;
int input = 10; // replace with std::cin or scanf()
doMath(d, input);
cout << "square of " << input << " = " << d->square << endl;
cout << "cube of " << input << " = " << d->cube << endl;
cout << "square root of " << input << " = " << d->squareRoot << endl;
}
Possible output:
square of 10 = 100
cube of 10 = 1000
square root of 10 = 3.16228
+ 2
I'm new here I'm sorry now I will take care all of these things
0
Ok! I will not break any of the rules