0

How can i find out a square,cube and square root of a number using pointers? In c language

20th Nov 2018, 6:44 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
6 ответов
+ 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."
20th Nov 2018, 7:17 PM
Babak
Babak - avatar
+ 3
You broke the TAGGING rule + didn't show us your best attempt, unfortunately!
20th Nov 2018, 7:21 PM
Babak
Babak - avatar
+ 3
Good luck, my friend!
20th Nov 2018, 7:23 PM
Babak
Babak - avatar
+ 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
20th Nov 2018, 7:11 PM
Babak
Babak - avatar
+ 2
I'm new here I'm sorry now I will take care all of these things
20th Nov 2018, 7:22 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
0
Ok! I will not break any of the rules
20th Nov 2018, 7:20 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar