Challenge

Hi everyone,

I just did the challenge and wanted to know if this was the “cleanest” way of doing it, I wanted to practice using a function. The output is correct, and I don’t think there is any shorter way of doing it but some of you might have some experienced input. Thanks!

[code]#include <stdio.h>

/*This challenge asks to write a program that computes and displays the square of an integer.
Then I need to put the numbers in quotation marks. The output should look like this:
“5” squared is “25”. */

// For this, I want to create a function that squares integers.

int squaredInt(int baseNumber)
{
return (baseNumber * baseNumber);
}

int main(int argc, const char * argv[]) {

int inputInt = 5;

//I will call the squarer function in the printf statement.

printf("\"%d\" squared is \"%d\".\n", inputInt, squaredInt(inputInt));
return 0;

}
[/code]

Your solution looks good. I’m a new programmer myself so I’m not sure which is the cleanest way, but I can show you how I did it:

So basically I called the printf() function inside the function we created rather than inside main(). Both good solutions though :slight_smile: