im have to write a program that calculates the square root of a number by using functions and pointers. If the number is less then 0, the function squareRoot should return 0 and print in main that the number cant be calculated. If the number is larger than 0, the function squareRoot should return 1 and print the answer in main
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int squareRoot(int *number)
{
if (number < 0)
{
return 0;
}
else if (number >= 0)
{
*number = sqrt(*number);
return 1;
}
}
int main()
{
int *num;
printf("Type in a number: ");
scanf("%d", &num);
squareRoot(&num );
printf("Square root = %d\n", num);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int squareRoot(int *number)
{
if (number < 0)
{
return 0;
}
else if (number >= 0)
{
*number = sqrt(*number);
return 1;
}
}
int main()
{
int *num;
printf("Type in a number: ");
scanf("%d", &num);
squareRoot(&num );
printf("Square root = %d\n", num);
return 0;
}
Comment